This tutorial was created with Visual Studio.NET 2008. 2005 can be used, but Microsoft's ASP.NET AJAX Extensions, which can be downloaded at this link, must be installed.
Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.
We all know that AJAX utilizes JavaScript, but what if we want to use our own JavaScript calls in conjunction with AJAX? This tutorial will show you how we can call JavaScript ourselves whilst using AJAX. We will be making use of the Alert method in JavaScript when the user clicks a button.
We will start off by creating our ASPX page with a ScriptManager and an UpdatePanel, as normal:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel> |
If you're ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.
For this web application, we will need to add a textbox and a button:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
Name: <asp:TextBox ID="txtName" runat="server" /><br />
<asp:Button ID="butJScall" runat="server" Text="Call JS" /><br />
<br />
Time: <%= DateTime.Now.ToString("T") %>
</ContentTemplate>
</asp:UpdatePanel> |
Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect and have been very happy. They are the most professional, customer service friendly and technically knowledgeable host we've found so far.
We add the current time to the UpdatePanel so we know when it refreshes.
Our button will call the following method when clicked:
| Protected Sub butJScall_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butJScall.Click
Dim script As String = "alert('Hi, " + txtName.Text + ". This is a JavaScript call within an UpdatePanel.');"
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "jsCall", script, True)
End Sub |
Need help with Windows Dedicated Hosting? Try Server Intellect. I'm a happy customer!
The entire code-behind will look something like this:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub butJScall_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butJScall.Click
Dim script As String = "alert('Hi, " + txtName.Text + ". This is a JavaScript call within an UpdatePanel.');"
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "jsCall", script, True)
End Sub
End Class |
To download this project, enter your email address and a link will be emailed to you.