Showing posts with label created. Show all posts
Showing posts with label created. Show all posts

Wednesday, March 28, 2012

Transparent PNG in AdRotator - Applying Behavior

I'm having a bit of trouble with AdRotator. I have images that are transparent PNG files. I created a style that applys the behavior to correct IE6 inability to display transparent PNG images. When I add the reference, images don't appear. They work in FireFox, just not IE6 (I haven't checked IE7). This behavior works everywhere else in the site.

Is there a workaround?

<asp:AdRotator id="AdRotator1" runat="server" borderstyle="None" datasourceid="SqlDataSource2" cssclass="adRotator"></asp:AdRotator>

.adRotator {
behavior: url('/behaviors/pngbehavior.htc');
border: 0px;
padding: 0px;
margin: 0px;
}

You need to haveheight andwidth set in AdRotator or CSS.

Tree view control with ajax

Hello,

I dont know, is this the right thread to post my prob. Here is my problem. I have a tree view control in a master page. I have created that tree view from "treeview.xml" file. I have created this file from database table. In this tree view, more than one node may have same name. My table has four fields - nodeid, nodename, parentid and lavel. The xml file looks like...

<?xml version='1.0' encoding='utf-8' ?>
<rootNode>
<siteNode title="root" id="1">
<siteNode title="my document" id="3">
<siteNode title="my films" id="31">
<siteNode title="bengalis" id="33">
<siteNode title="aaa102" id="102" />
<siteNode title="aaa106" id="106">
<siteNode title="xxxx1" id="1051" />
<siteNode title="xxxx1" id="1053" />
<siteNode title="zzzz2" id="1059" />
...
...
Every node may have more than one information. All these informations are stored in a different file with "nodeid". What I want is that when any one click on any node I want to display all the information stored in that node in the "Conten Page" with the help of Ajax. For that I need the id of that selected node. How can I access the node id?

Angshujit

Do you want the tree view to dynamically add nodes when you click one of the nodes? If so, you will have a lot of problems using the built in controls for that because the treeview is not supported inside an update panel. You can generally have a treeview in an update panel if it doesn't change the contents, but if you want it to change after page load, you should look at getting a 3rd part control for it.

Hello,

Thank you for your reply. No, I dont want so at present. Actually what is became my headache is how to get the id of the node.

protectedvoid SelectedNodeChanged(object sender,EventArgs e)

{

string id = treeView1.SelectedNode.?

Because without knowing the id I cannot search the table for contents belongs to that node. I cannot usetreeView1.SelectedNode.Text becasue there may be more than one nodes with same text. Is there any way to solve it? Please help me.

Angshujit

Treeview + Update Panel

Hi!

I'm working on atlas and I'm testing some functionnality. I created a page with a treeview contained in an update panel and another update panel that shoul be updated when one selects a node but it doesn't work. Can someone help me?
Here is th source code:

<%@dotnet.itags.org. Page Language="C#" %>"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> void dataBound(Object sender, TreeNodeEventArgs e) {// Determine the depth of a node as it is bound to data. // If the depth is 1, show a check box. if (e.Node.Depth == 2) { e.Node.ShowCheckBox = true; } else { e.Node.ShowCheckBox = false; } } protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) {//If a node is selected, display the text in the right table Message.Text = TreeView1.SelectedNode.Text; }</script><html xmlns="http://www.w3.org/1999/xhtml" >First TreeView with an XML File"server"> "text/css"> div.global { width:100%; margin:0px; border:1px solid #99ccff; line-height:150%; } div.header,div.footer { padding:0.5em; color:white; background-color:#99ccff; clear:left; } div.left {float:left; width:200px; margin:0; padding:1em; } div.right { margin-left:270px; border-left:1px solid #99ccff; padding:1em; } "form1" runat="server"> true ID=ScriptManager runat=server/>

class=global>

class="header">Dynamic Atlas Tree View

class=left> "TreeView1" runat="server" DataSourceID="XDS" OnTreeNodeDataBound="dataBound" ShowCheckBoxes=None OnSelectedNodeChanged="TreeView1_SelectedNodeChanged" ShowLines=true> "Kpf" ValueField="ID" TextField="Name"/> "Activity" ValueField="Value" TextField="Value"/> "XDS" runat="server" DataFile="~/XMLTVDataSource.xml">

class=right> Selected elements



"TreeView1" EventName="SelectedNodeChanged "/>

class=footer>KPF Nord

There is a bug with the TreeView. If you remove ShowLines (or set it to false) it should work. When ShowLines is set to true, the controlsometimes generates invalid xhtml.

For more details, check out this post:
http://forums.asp.net/forums/1196633/ShowPost.aspx


Thanks for your reply. This is the error generated when I debug:
"The EventName must be set to a valid event name on the associated control"
And it occurs because of the triggers tag.
Could someone help me to fix this problem?

treeview in Multiview clientscript problem in new beta

Hi,

I have a problem with one of my web page... for debugging purpose I created a simple test webpage to explain the problem.
Here it is:
An updatepanel containing a multiview.
In this multiview there's 2 view, each containing a tree view and a button to go to the other view.
The default activeview is the first one.

My problem is that only the treeview in the first view works.
The treeview in the 2nd view crashes with error "Microsoft JScript: 'TreeView2_Data' is undefined." when I click a node.
Of course if I set the enableclientscript property of the treeview to off then it works okay but it does a partial postback at each node collapse-expand...

My guess is that the clientscript is not injected correctly on view change but how can I fix that ?
Btw it used to work before I updated to Beta 1.0

Thanks a lot !

Jean-Sébastien Roy

I was able to repro it and report it to the developer..

thanks for the report....

Andres


Hi,

The TreeView control is not supported inside UpdatePanels in Atlas 1.0. A future release of Atlas will support this scenario. In Atlas 1.0 you can have the TreeView outside the UpdatePanel.

Thanks,

Eilon


Thanks to you both for the fast answers !

Placing a TreeView inside an UpdatePanel is not supported on the Beta. Please look a the following documentation page (under the "UpdatePanel Compatible Controls"):http://ajax.asp.net/docs/Overview/intro/partialpagerendering/updatepanelOverview.aspx. Full support for all controls will be available on the next release of ASP.NET.

Thanks,
Federico


I had a same problem. Seems like its not supported in Beta version. Does anyone know of a workaround?

Thanks


Hi,

UpdatePanel control is used for only partial updating/partial_page rendering. You can not use the updatePanel control for Treeview and someother controls like MenuView and FileUpload.

If you need more help on this check in below link under UpdatePanel Control.

http://ajax.asp.net/default.aspx

Pradeep Kumar

Monday, March 26, 2012

TreeView populated programatically in Atlas UpdatePanel

Hi there,

I'm fairly new to Atlas and ASP.NET, so perhaps this question is obvious (I apologise).

I have created a page which essentially contains this information:

<asp:Content ID="Content1" ContentPlaceHolderID="MainPagePlaceholder" Runat="Server">
<atlas:UpdatePanel ID="AjaxMultiMediaPanel" mode="Conditional" runat="server">
<ContentTemplate>
<asp:Table ID="MultiMediaTable" CssClass="MultiMediaTable" runat="server" Height="193px" Width="274px">
<asp:TableRow runat="server">
<asp:TableCell runat="server" CssClass="TableTopAlign">
<cc1:MediaPlayer ID="MediaPlayer1" runat="server"></cc1:MediaPlayer>
<atlas:UpdateProgress runat="server" ID="progress">
<ProgressTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/SpinningBall.gif" /> Reading UPnP Directory
</ProgressTemplate>
</atlas:UpdateProgress>
</asp:TableCell>
<asp:TableCell runat="server" CssClass="TableTopAlign">
<asp:TreeView ID="TreeView1" runat="server" >
<ParentNodeStyle CssClass="TreeParentNodeStyle" />
<HoverNodeStyle CssClass="TreeHooverStyle" />
<RootNodeStyle CssClass="TreeRootNodeStyle" />
<LeafNodeStyle CssClass="TreeLeafStyle" />
<NodeStyle CssClass="TreeNodeStyle" />
</asp:TreeView>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Play" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Load UPnP Info" />
</asp:TableCell>
<asp:TableCell>
<asp:Label ID="Label1" runat="server" Text="" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ContentTemplate>
</atlas:UpdatePanel
</asp:Content>

When Button2 is pressed, I programatically populate the TreeView (using c# to recursively build the tree). This works without problems when I do NOT use Atlas, except of course in that case the page refreshes after about 10 seconds. Now, using the code above, The Progress Update image and text is shown for about 10 seconds, but after that the page 'freezes' for over a minute. I have tried triggers to force a refresh, programatically forcing a refresh, but nothing helps. If I at the end of my tree-population code turn set TreeView1.Visible = false; then the page does not freeze.


It appears that the population of the treeview somehow causes Atlas to do 'something' for an awful long time.

If possible, I would appreciate any help any of you experts can offer.

- Anders

P.S. The tree has a depth of about 4-5 levels max, with about 100 items. Nothing crazy. The 10 second delay is due to some other UPnP lookups I'm doing, not because it takes a long time to build the tree.

See also:similar discussion

A count of my items reveals 2685 of them, a bit more than stated above.


Hi Anders

Did you ever find out a solution to this problem? I have been having the same problem where a TreeView inside an UpdatePanel takes a very long time to refresh.

Using Fiddler, I found out that the problem is the various images used by the TreeView control. Outside an UpdatePanel, the browser makes only one request for an image, regardless of the number of times its used. Inside the UpdatePanel, the browser makes a request for each and every instance of an image.

I don't know if this is a problem with the IE cache or the way Atlas is processing the resulting page.

The solution to this has so far eluded me. The only thing I can do is to reduce the number of images used by the TreeView control, but that quickly makes it useless.

Cheers,

- Dan


Hi Dan,

No solution so far. I had to drop it and just create the site using other widgets. Not quite as cool, but at least it works.


http://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx#UpdatePanelCompatibleControls

I had same problem. Finally, I setup a full postback trigger to the control that will force the repaint.
In my case, I had a button so my trigger code look like this:
<Triggers>
<asp:PostBackTriggerControlID="btnBack"/>
<asp:PostBackTriggerControlID="btnNext"/>
</Triggers>


I had the same problem, but I am still using Atlas, I don't wanna update until official version. And atlas UpdatePanel does not have PostBackTrigger, do you know how to solve it this problem witt Atlas?
If you haven't upgraded to the latest version by now, then you're going to be in a world of hurt when the RTM is released. There have been MANY breaking changes from ATLAS and it would be wise to forget ATLAS and move forward.

trigger for control that is dynamically created on databind

I have a dropdownlist that is created when the gridview is databound. This is because the dropdownlist is contained in the headertemplate of a templatefield column. So I have tried to add the trigger dynamically right after the gridview is databound, but I keep getting an error saying that the controlID wasn't found...I don't know what is wrong. I can find the control inside the the gridview with no problem using the findControl fuction.


TimeStampGridView.DataBind();
DropDownList StatusFilterDLL=(DropDownList)TimeStampGridView.HeaderRow.Cells[2].FindControl("StatusFilter");//finds the Control
StatusFilterDLL.SelectedIndex = StatusFilterDLL.Items.IndexOf(StatusFilterDLL.Items.FindByText(StatusFilter));//Works fine
AsyncPostBackTrigger trigger =new AsyncPostBackTrigger();
trigger.ControlID ="StatusFilter";
trigger.EventName ="SelectedIndexChanged";
GridUpdatePanel.Triggers.Add(trigger);//error:A control with ID 'StatusFilter' could not be found for the trigger in UpdatePanel 'GridUpdatePanel'


Anyone know what I'm doing wrong here?

Thanks for the help in advance!

I removed all the code for the dynamic trigger and set the dropdownlist's autopostback= true so now when the user changes the selectedindex the gridview is updated

Trigger full postback from the server during a partial postback.

Well, I have a dialog user control (ajax popup) which can again contain other user asp user controls as content. The content of the dialog is created inside an UpdatePanel, so that the dialog content can postback. All of that works OK.

On the web page I have now some information visible inside a GridView which is not in an UpdatePanel and should not be, because I need the browser forward/backward button to work. A link on that web page lets one of these dialog controls pop up. The dialog contains a user control which can manipulate the data which is visible inside the GridView. If the user presses a button inside the dialog, the dialog does an asynchronous postback as the user control/dialog content is inside an update panel and the dialog closes. That gives the user the impression that nothing happened as the data visible in the GridView did not change. I do already have the code to refresh the gridview, but how can I change the behavior during the postback from being an asynchronous postback to a full postback?

So just to clarify some pseudo code:

In the user control contained inside the dialog I would have some code like:

void OnOK(...)
{
// check if any data changed
if (textBox.Text != record.Text)
{
// do a database update
// and
// update cached data which the datagrid is bound to
// call a method on the page to rebind the datagrid only

// ? Force a full page refresh
}
else
{
// do nothing
// asynchronous postback is OK, no full page refresh needed
}
}

The force of a full page refresh is what I would need. In a fat environment like Windows Forms, I would just call Invalidate on the Form. Or IF the DataGrid would be inside an UpdatePanel I would search for it and call Update() on it, but then I would loose the browser caching during back and forward movements. So I was searching through all of the classes if there is something like ScriptManager.UpdatePage or something similar, but have found nothing so far.

So what is the solution here? How can inform the ajax client side script, that it should just go ahead and rerender the whole page instead of just extracting the update panel portions?

Thanks

In the <Triggers> collection of your updatepanel, just add whatever control you want to cause a full refresh as a PostBackTrigger instead of as a AsynchPostBackTrigger.

<asp:UpdatePanel ...>
<Triggers>
<asp:PostBackTrigger ControlID="whateverID" />
</Triggers>
<ContentTemplate>
...
</ContentTemplate>
</asp:UpdatePanel>


Well, that does not work:

a) the UserControl is designed separatly and does not have an update panel and vice versa the dialog is a generic control which just adds a UserControl as a content, so it cannot hardcode if there is any control ID inside which should trigger a full postback

b) I do not want a full postback to occur all the time when the button is pressed, the logic of the button on the server side should determine if a full postback is necessary or not, if not then a partial postback is OK.


I tried to work around now, kind of using your approach by doing this in the OnPreRender or OnChildControlsCreated of the UserControl:

System.Web.UI.WebControls.WebControl btnOK =this.Parent.Parent.FindControl("btnOK")as System.Web.UI.WebControls.WebControl;
if (btnOK !=null)
{
System.Web.UI.Control control = btnOK;
UpdatePanel updatePanel = control.ParentasUpdatePanel;
while ((updatePanel ==null) && (control !=null))
{
control = control.Parent;
updatePanel = controlasUpdatePanel;
}
if (updatePanel !=null)
{
PostBackTrigger pbTrigger =newPostBackTrigger();
pbTrigger.ControlID ="btnOK";
updatePanel.Triggers.Add(pbTrigger);
}
}

So I do find the OK button and I do find the UpdatePanel that contains the button, but it has no effect whatsoever.
The control ID must be right, otherwise I would not be able to find the button with it, but still no PostBack and the Dialog itself is not inside an UpdatePanel.

Saturday, March 24, 2012

Triggering Dynamic Controls

Hi,

I got several Textboxes which are being created dynamically.

private TextBox CreateTextBoxes(int i)
{
TextBox tb = new TextBox();
tb.Width = 30;
tb.Height = 20;
tb.CssClass = "inputfield";
tb.ID = "TextBoxID" + i.ToString();
tb.Text = i.ToString();

Microsoft.Web.UI.ControlEventTrigger trig = new Microsoft.Web.UI.ControlEventTrigger();
trig.ControlID = this.FindControl(tb.ID.ToString()).ToString();
trig.EventName = "CheckChanged";
UpdatePanel1.Triggers.Add(trig);

return tb;
}

Throws an Error at FindControl:Object reference not set to an instance of an object.

When I don't use FindControl it compiles but the Event is never triggered. The dynamic Controls are wrapped in a static UpdatePanel1 via the designer.

Is that possible at all with Atlas yet?

The problem with this code is that you never added the dynamically created text box to any control collections. FindControl() works by traversing the controls collections, and control are only rendered (unless you call RenderControl() yourself) if they appear somewhere in the control collection tree for a page.

Actually, you have no reason in the code segment above to call FindControl(), because you have the class instance local to that scope. You would only use FindControl() to retrieve a control instance where you have no local variable assigned or had no way to retrieve the instance using other means.

The reason you never see the trigger is because the control you created in the code was never attached to anything that would have ended up visible on the client. If you added the control to the collection for after this code segment, you have no guarantee that the actual control ID generated once the page is rendered would be the same as you assume in this code, since control ID's actual values depend on their placement within the naming container "tree" starting from the page down.

My suggestion would be to never do anything that assumes a consistent control ID (and UpdatePanels depend on this for handling a variety of things on the client side) with a dynamic control until you have added it to a control collection that is attached to a page already. Then all the things that need to be wired to make your triggers (or commands or events) work will work.


The textbox method is called in a foreach loop, mostly about 4-6 textboxes are being created.

Is this maybe possible with the new Dynamic UpdatePanel featured in the new Atlas build?
The new UpdatePanel in the June CTP certainly does change the dynamics of the problem you described.

Wednesday, March 21, 2012

trouble finding a sample using usercontrols and updatepanels

Hi all,

We have created a menu system primairy based on inserting usercontrols inside one single designed page with several areas's. This works very nice for our sites. Of coarse postback occurs on every click or change.

Some functionality inside usercontrols do a lot of postback, so I would be nice to use the update panel for this type of change.

When trying to implement this I ran into all sorts of trouble, so my first step is to hit this forum. From what i find i'm not the only one having some trouble using usercontrols in combination with the update panel.

So question: Does anyone have a working sample which i could have a look at. Probably can't use it 1 on 1 but well it would a nice starting point.

thanks,

-- jan willem

ps. Does anyone notice .. that all the the ajax stuff (including of coarse atlas) looks REAL nice but when u start to implement it it does realy really takes a lot of time learning to program again :-) Well it's new (ehh well kinda), better and customers do love it.

I wrote a sample to have a test with Ajax and User Control.

http://www.box.net/public/static/q4ltbl5an9.zip

It's simple and straight forward:

1. One user control is linkbutton group, auto generated during runtime;

2. Another user control is to display information according to the user control above;

3. Event subscription is used for information delivery.

4. The link which clicked should be set into different style.

Hope it's helpful.

This was researched days before, now I'm running into the problem of Atlas in live.com. It seems doesn't work with EFP at all!


Thanks for the sample it is usefull!

The only trouble is that the atlas controls (scriptmanager, updatepanel) are still created in the page and not in the usercontrol.

I've created a very simplistic sample of what i'm looking for. Just a page and a usercontrol. I put them in the link below.

http://www.bataviagroep.nl/sampleAtlasUC.zip

- default.aspx --> no atlas, just page and usercontrol doing what it should do .. handling click
- atlas-page.aspx --> same as above, all in one page using atlas and working fine (i added the picture so it's very clear that only the notfication changes

- default-atlas.apsx (same as the first default.aspx) but with the atlas inserted in the usercontrol. This one throws the following exeption:

"The UpdatePanel 'UpdatePanel1' was not present when the page's InitComplete event was raised. This is usually caused when an UpdatePanel is placed inside a template."

For those who don't like downloading stuff from a different server:

default.aspx
<body>
<formid="form1"runat="server">
<div>
<asp:PanelID="panel1"runat="server"/>
</div>
</form>
</body
code behind:
ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load

panel1.Controls.Add(Page.LoadControl("~/uc-atlas.ascx"))

EndSub

The usercontrol uc.ascx
<asp:LinkButtonID="LinkButton1"runat="server">click A</asp:LinkButton>
<asp:LinkButtonID="LinkButton2"runat="server">click B</asp:LinkButton>
<br/><br/>
<asp:LabelID="Label1"runat="server"Text="Label">not clicked</asp:Label
code behind:

ProtectedSub LinkButton1_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles LinkButton1.Click

Label1.Text ="clicked A"

EndSubProtectedSub LinkButton2_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles LinkButton2.Click

Label1.Text =

"clicked B"EndSub

The same user control but then with atlas stuff added:

<atlas:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="true">

</atlas:ScriptManager>

<asp:LinkButtonID="LinkButton1"runat="server">click A</asp:LinkButton>

|

<

asp:LinkButtonID="LinkButton2"runat="server">click B</asp:LinkButton>

<

br/>

<

br/>

<

atlas:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:LabelID="Label1"runat="server"Text="Label">not clicked</asp:Label></ContentTemplate><Triggers><atlas:ControlEventTriggerControlID="LinkButton1"EventName="Click"/><atlas:ControlEventTriggerControlID="LinkButton2"EventName="Click"/></Triggers>

</

atlas:UpdatePanel>

code behind is the same as above.

--> the above doesn't work and throws an expection.

I would love a sample or idea how to fix this

thanks,

-- jan willem

ps. all the code is in the zipfile


load the custom user control in the Page_Init event, it will work then

wow that worked ...

great that was th easy asnwer i kept missing thanks!

--jw


You might try putting a Placeholder control inside the content template of the UpdatePanel, use FindControl() on the UpdatePanel to locate the Placeholder, and use Placeholder.Controls.Add() to add your dynamically created user control from LoadControl().

The key here is that the container for the user control must exist before OnInit(), and the only way to accomplish this is the declaratively put something there first.

I have gotten this scenario to work. Adding anything directly to the UpdatePanel after OnInitComplete() will not work.

True Asynch streams using IE

I created a page in ASP.Net that does the following:
Output line #1
{wait 1 second}
Output line #2
{wait 1 second}
Output line #3
....etc
If I browse to the page, you can see that the response comes back as a STREAM, as it happens. (Note you can only see this the SECOND time the page is loaded in IE)
When I use XmlHttp in IE, the response only comes back when the WHOLE page is done. However, in other browsers, it works as expected. The onreadystatechange raises the event in my JS callback function when the document is complete, but FireFox raises it for each FLUSH, which is the effect I need. I would like to know if anyone else can make IE XmlHttp object do the stream.
Example code: (C#)

privatevoid Page_Load(object sender, System.EventArgs e)
{
Response.ClearContent();
Response.BufferOutput =false;
Response.Write("Output line #1<br/>" + CRLF);
Response.Flush();
System.Threading.Thread.Sleep(1000);

Response.Write("Output line #2<br/>" + CRLF);
Response.Flush();
System.Threading.Thread.Sleep(1000);
//etc..
Techniques I have tried:
1) Asynch Http Module - the module worked, but the client side still did not
2) JavaScript work arounds:
a) Polling
b) Remote Scripting (this works, but must use a GET, and so is not as secure)
c) Timeouts (too many requests)
3) HTA - also works, but only on IE
Any help would be appreciated!

It looks like this problem is with Internet Explorer and not just XmlHttp object
I put an example up onhttp://www.ECMASCRIPT.net/
If you click on the link in Firefox you get the document as it streams.
If you click on the link in IE, it waits until the whole document is done the first time. If you hit refresh on /TimedOutput.aspx you get the same as firefox.

The button simply uses the Xmlhttp object to request the same page and display the result as it get it. It works well in fireFox, but not IE

Is this a header problem? Or did I set up IIS wrong? Can I write my Asp.Net Page any way to fix this?

Any help would be appreciated!

trying to deserialize json to a C# class - do I use .Deserialize? .Deserialize<>?

Hello,

I have several classes that have been rendered to the client, each with their respective __Type properties. I have created a generic save() webmethod that I would like to invoke, passing any of the various serialized classes. But each attempt fails with various runtime errors. My original intent was:

[WebMethod]
public string save(object obj)
{
obj.save() // obj is casted to one of several c# classes depending upon the __Type property present
}

And I hoped/assumed that .NET Ajax would handle my deserializtion which it did not. My next attempt was to make the obj variable a string type and then try and deserialize manually inside the method. I have done this quite easily in the past with AjaxPro.

[WebMethod]
public string save(string obj)
{
System.Web.Script.Serialization.JavaScriptSerializer jser = new System.Web.Script.Serialization.JavaScriptSerializer()
myobj = (cs_class)jser.Deserialize<cs_class>(obj);

myobj.save();
obj.save() // obj is casted to one of several c# classes depending upon the __Type property present
}

I am now looking at System.Web.Script.Serialization.JavascriptSerializer.Deserialize<> and System.Web.Script.Serialization.JavascriptSerializer.DeserializeObject() but the documentation is sparse and there is no sample code and I'm not even sure I'm looking at the right thing.

Could anybody help me with this please?

Troy

In the case below, ASP.NET Ajax would deserialize the object to right type.

[WebMethod]
public string save(object obj)
{
obj.save() // obj is casted to one of several c# classes depending upon the __Type property present
}

However this only happens for the types that corrospond to type proxy that is generated (This way server side has control over what types can instantiated during deserialization). Please include [GenerateScriptType(typeof(YourType))] to your service class, for all the possible types that can be passed to 'save' webmethod.


In the case below, ASP.NET Ajax would deserialize the object to right type.

[WebMethod]
public string save(object obj)
{
obj.save() // obj is casted to one of several c# classes depending upon the __Type property present
}

However this only happens for the types that corrospond to type proxy that is generated (This way server side has control over what types can instantiated during deserialization). Please include [GenerateScriptType(typeof(YourType))] to your service class, for all the possible types that can be passed to 'save' webmethod.


Ankit,Thanks for your answer. However, I am still unsure where to continue from here. Obj is type object, a builtin C# type that I am using as a placeholder since I don't know what I am going to receive from the client. I can't call obj.save directly since it will try and call a save() method on the builtin object type (that doesn't exist). How do I coerce obj into thinking it is one of my allowable types? Moreover, the type that was actually received?

Also, I have added the [GenerateScriptType... decoration but I don't think it was needed. My classes were already successfully serialized to the client. When I inspect the DOM I can see all of my allowable classes and when I inspect the contents of the XHR post I see the full json text including __Type:

Troy


Sorry I somewhat misread your question ( I thought you said deserialization is not being handled properly by ASP.NET Ajax). Yes if the type is already referenced by your service class then you don't need the GenerateScriptType decoration.

Once you get Obj of type Object, you can call Obj.GetType() to get the type of the object. Based on the type you would need to cast to the type , and then call .save(). If you have control over the definations for all the types that you need to call .save() on , a better thing would be to define an interface with .save() method, and have all the types implement that interface.


Ankit, thank you so much. You've answered my first and most fundamental question which is "can it be done?" I understand conceptually what you are saying but I'm unsure how to actually implement it. I have control over all the interfaces. I have created an abstract class called Asset and then derived Bookmark and Collection from it. Both Bookmark and Collection override the abstract save() method. If you have the time would you be able to offer some sample code?

Thanks,

Troy


In a related question how can I go about ensuring the __Type property is present?

One of my webmethods is called getTemplate()

 [WebMethod] [ScriptMethod(UseHttpGet =true, ResponseFormat = ResponseFormat.Json)] [PrincipalPermission(SecurityAction.Demand, Role ="Users")]public adbeast.myadbeast.collection getTemplate() {return new adbeast.myadbeast.collection(); }

and it returns

{"__type":"adbeast.myadbeast.collection","collectionType":0,"id":0,"parentId":null,"title":"","description":"","urlIcon":"","ace":0,"assetsUpdated":false,"usernameCreated":"","usernameModified":"","dateCreated":"\/Date(-62135578800000)\/","dateUpdated":"\/Date(-62135578800000)\/","assetIds":{"BOOKMARK":[],"IMAGE":[],"NEWSSUBSCRIPTION":[],"SPOT":[]},"assetType":1}
I have another webmethod
  
 [WebMethod] [ScriptMethod(UseHttpGet =true, ResponseFormat = ResponseFormat.Json)] [PrincipalPermission(SecurityAction.Demand, Role ="Users")]public List getAssets(Int64[] arrAssetIds) {return adbeast.myadbeast.user.getAssets(currentUser.userName.ToString(), arrAssetIds); }
 that returns
 [{"collectionType":0,"id":72,"parentId":0,"title":"My Collection","description":"","urlIcon":"/thumbnails/","ace":31,"assetsUpdated":false,"usernameCreated":"troyf","usernameModified":"troyf","dateCreated":"\/Date(1179432532950)\/","dateUpdated":"\/Date(1179432577013)\/","assetIds":{"BOOKMARK":[92,93,94,95,96,70,71,70],"IMAGE":[],"NEWSSUBSCRIPTION":[],"SPOT":[]},"assetType":1}]  

I am not receiving the __Type property in the second example. Should I be writing a custom Converter for my classes? I am looking at http://ajax.asp.net/docs/mref/T_System_Web_Script_Serialization_JavaScriptSerializer.aspx and the examples but there is no indication that __Type is created if I build a custom converter.

Troy


Are both these methods in the same web service?


They are in separate webservices.

T.


Try adding [GenerateScriptType(typeof(adbeast.myadbeast.collection))] to the service class in second case. __type is only added for types that are for parameter types , return types for webmethods, and types in GenerateScriptType decorations.

two-way property synching not working...

I have an ajax extender that was created using the AjaxControlToolkit "ASP.Net AJAX Extender Control" wizard. My extender derives from AjaxControlToolkit.ExtenderControlBase.

My class has a bunch of properties that have the ExtenderControlProperty and ClientPropertyName attributes. These properties sync just fine from server to client, but I can't seem to get them to sync from client to server. Using this.set_ClientState("xyz") on the client gives me a value that is readable in the ClientState property on the server, but that is cheating since it uses a hidden input element.

Yes, I call this.raisePropertyChanged("MyValue") in the client JS when the property changes, and I have ensured that raisePropertyChanged is actually be called (via debugger).

Any ideas?

Nobody has any suggestions?