Sunday, December 19, 2010

ASP.NET 4.0- ScriptManager Enhancement Part-I- Enable CDN Property.

ASP.NET 4.0 has been a great step forward to the programming. Microsoft has done incredible job with the performance. One of them is Enable CDN Property in asp.net 4.0 Script Manager. Let's explore it in details. As you all know that Microsoft is Providing Content Delivery Network for all the Ajax script that is used by Microsoft Ajax and All version of Jquery and JQuery UI. This Script manager enable cdn property will fetch all the script from that CDN Automatically. Developer don't have to worry about. As you know new generation browsers are like IE8 and Firefox are creating a new thread of each JS or CSS include in Webpage if they are coming from the CDN(Content Delivery Network). So this will be a great measure step towards it. Let's take an example to explore the things. I am taking one simple example which will demonstrate use of this. I am tasking a Textbox and Button. On the button click event it will update textbox's text property. I am going to use update panel to use Microsoft Ajax. For that first I need a script manager so I have taken script manager and and I have set its property EnalbleCdn=true. So without posting back whole it post back only that portion which are required. I have putted textbox in content template of update panel and I have created asynchronous post back trigger for button click event. So it will update the textbox text without creating post back. Let's how I have created. Following are Simple HTML for that.
<body>
<form id="form1" runat="server">
<div>

<asp:ScriptManager ID="cdnScriptManager" EnableCdn="true" runat="server">
</asp:ScriptManager>  

<asp:UpdatePanel ID="cdnUpdatePanel" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtHelloWorld" runat="server"></asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnHelloWorld" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<BR />
<asp:Button ID="btnHelloWorld" runat="server" onclick="btnHelloWorld_Click"  Text="Hello World!!"/>


</div>
</form>
</body>

Now I am going to create a click event which will change textbox text’. Following is a code for that.

protected void btnHelloWorld_Click(object sender, EventArgs e)
{
txtHelloWorld.Text = "Hello World";
}

That’s it Let’s run that with Ctrl+ F5 and It will look in firefox browser like following.


ScriptManager4.0, ASP.NET 4.0 Enhacement


Now Let’s see its view source and see how it’s look like. Following is a screenshot of view source.


ViewSource

As you can see its fetching all the JS from Microsoft Ajax Content delivery network. Isn’t that great. You just to have enable CDN Property =true and It will do rest of Job. That’s power of asp.net 4.0. Hope you liked it. Stay tuned for more in Part 2.
Shout it
Share:

0 comments:

Post a Comment

Your feedback is very important to me. Please provide your feedback via putting comments.

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews