onsdag 13 februari 2008

Don't be to quick on blaming the Ajax Accordion

The ASP.NET Ajax Accordion control is a powerful and easy to use control to create nice GUI.

However, the Accordion has one famous bug related to server side buttons located inside an AccordionPane (More on that bug here).

When having problems with server side controls located in an AccordionPane you are therefore quick to blame the Accordion for controls that does not trigger or work properly. So, you end up spending a lot of time trying to make it working using all dirty hacks you can Google on this issue.

Exactly this happend to me recently.
In this case I had two AccordionPanes, one with the button and one with a UserControl containing Textboxes as well as a few Validators. As I couldn't see neither the textboxes nor the validators the result was that of course, my button triggered the validators which probably displayed their message in the hidden AccordionPane...but for me, I blamed it all on the Accordion and started to Google and tweak it to obey my will. I even removed the whole thing and created an AnimationExtender to the exact same thing...

Conclusion; use your basic knowledge first when it comes to finding bugs.

onsdag 6 februari 2008

ASP.NET Ajax Services

A simple but yet powerful feature in ASP.NET is the ability to call a server side Webservice using Javascript.

Simple add an <asp:ServiceReference> node to your <ScriptManager>, example:
<asp:ScriptManager ID="sctMgr" runat="server">
<Services>
<asp:ServiceReference Path="~/AjaxService/Service.asmx" />
</Services>
</asp:ScriptManager>

Assume that you in your "Service.asmx" have the following declaration:
[WebMethod()]
public string UpdateData(string inputData)
{
//do something with "inputData"...

//return something...
return DateTime.Now.ToString();
}


This will enable us to do the following from a javascript:
<script type="text/javascript">
Service.UpdateData("ABC");
</script>


Using Visual Studio 2008 you will even get intellisense for the Web Methods in your service.

To retrieve the return value from the Web Method we simply add a call back method:
function OnServiceUpdateComplete(result)
{
alert("The Result from the Web Method call was: " +result);
}


...and associate it with the service call:
<script type="text/javascript">
Service.UpdateData("ABC", OnServiceUpdateComplete);
</script>