Lindsay Donaghe's personal annotations on this page
Good arguments against over-use of UpdatePanels and some sample script of how to replace their functionality with JSON calls.
-
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods="true" />
<script language="javascript">
function UpdateTime() {
PageMethods.GetCurrentDate(OnSucceeded, OnFailed);
}
function OnSucceeded(result, userContext, methodName) {
$get('Label1').innerHTML = result;
}
function OnFailed(error, userContext, methodName) {
$get('Label1').innerHTML = "An error occured.";
}
</script>
<asp:Label runat="server" ID="Label1" Text="Update Me!" /><br />
<input type="button" id="Button2" value="Web Method Update"
onclick="UpdateTime();" /> -
[WebMethod]
public static string GetCurrentDate()
{
return DateTime.Now.ToLongDateString();
}
This link has been bookmarked by 9 people . It was first bookmarked on 30 Sep 2008, by Lindsay Donaghe.
-
Kiernon ReinigerGood article on the use of EnablePageMethods property of the ScriptManager
-
-
Using JSON, the entire HTTP round trip is 24 bytes, as compared to 872 bytes for the UpdatePanel. That’s roughly a 4,000% improvement, which will only continue to increase with the complexity of the page.
Not only has this reduced our network footprint dramatically, but it eliminates the necessity for the server to instantiate the UpdatePanel’s controls and take them through their life cycles to render the HTML sent back to the browser.
While I’m a proponent of the simplicity inherent in the UpdatePanel, I think that it is crucial that we use them judiciously. In any heavy use situation, they are very rarely the best solution.
-
-
Lindsay DonagheGood arguments against over-use of UpdatePanels and some sample script of how to replace their functionality with JSON calls.
-
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods="true" />
<script language="javascript">
function UpdateTime() {
PageMethods.GetCurrentDate(OnSucceeded, OnFailed);
}
function OnSucceeded(result, userContext, methodName) {
$get('Label1').innerHTML = result;
}
function OnFailed(error, userContext, methodName) {
$get('Label1').innerHTML = "An error occured.";
}
</script>
<asp:Label runat="server" ID="Label1" Text="Update Me!" /><br />
<input type="button" id="Button2" value="Web Method Update"
onclick="UpdateTime();" /> -
[WebMethod]
public static string GetCurrentDate()
{
return DateTime.Now.ToLongDateString();
}
-
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.