Showing posts with label methods. Show all posts
Showing posts with label methods. Show all posts

Monday, March 26, 2012

Treeview Malfunction In Update panel

If I put a treeview in an update pannel and put any code in its expand /collapse methods the treeview closes the previous node that you expand. This is fine but when I expand a node and try to collapse that same node it does not collapse but rather stay expanded. Therefore I gathered it does the opposite action to the previously clicked node.

Why does this happen in the update panel, it doesn't happen without it?

The treeview control is not supported officially in the updatepanel!

One problem is that (I think) the treeview use hidden fields to maintain the expanded state of the nodes, and that hidden field stay out of the sync (especially when you use EnableClientScript="true" also). There are tons of other treeview features which not works correctly in the updatepanel.

Wednesday, March 21, 2012

Trying to pass JSON objects to C# methods

Hello,

I am trying to overload a webmethod unsuccessfully. I recall reading that webmethods can not be overloaded since SOAP does not support that. If I only intend to make my webmethods accessible from javascript/JSON is there a way to force ASP.NET to accept overloaded webmethods?

My current workaround uses a brokering method that actually test the type (from __Type) and branches accordingly.

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[PrincipalPermission(SecurityAction.Demand, Role = "Users")]
public status save(object obj)
{
status stat;
switch (obj.ToString())
{
case "collection":
stat = collectionSave((collection)obj);
break;
case "bookmark":
stat = bookmarkSave((bookmark)obj);
break;
default:
stat = new status(999, "save(): did not find method for " + obj.ToString());
break;
}

return stat;
}

On my client I can simply call save() and pass in any of the allowable JSON objects that exist on the page. However, this seems to be a klunky way of doing things. Is there a better way? If I create overridden methods the compiler does not complain, but it seems that only the final method in the list of methods is the one called, regardless of the type passed in.

Thanks,

Troy

The main problem seems to be thatwebmethods can not be overloaded since SOAP does not support it.

I'm afraid that we haven't any better ways to do that.