Hi,
Here we will create a simple ASP.Net Ajax webpage having a button and textbox control in it.
On the click of button we will fill the textbox with “Hello world” string returned from the server without refreshing our webpage.
1) Create a new ASP.NET Ajax web site(Visual Studio 2005)or ASP.NET web site (version 3.5) if we are using Orcas(Visual studio 2008)
2) Add a ScriptManager control in the page( if it isn’t there)
3) Add button and textbox server side control.
<asp:TextBox ID=”TextBox1″ runat=”server” />
<asp:Button ID=”Button1″ runat=”server” Text=”Button” />
4) Add this event Handler for button click event
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text=”Hello World”;
}
4) Now to make our page AJAX enabled the only thing we need to add is
<asp:UpdatePanel id=up1 runat=server>
<ContentTemplate>
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
<asp:Button ID=”Button1″ runat=”server” onclick=”Button1_Click” Text=”Button” />
</ContentTemplate>
</asp:UpdatePanel>
Just wrap our server side controls inside update panel control’s content template.
5) That’s it. Now run the application and click on the button the textbox should get filled with Hello World string without any refresh of the page.
Right now what we saw was a server-centric approach using updatePanel control.
We can do the same thing using client-centric approach using ASP.NET AJAX client library. Check this post
https://nishantrana.wordpress.com/2007/11/06/creating-and-calling-aspnet-ajax-web-service/
Bye.
Thanks, i just needed very basic to start my ajax works and this helps me.
LikeLike
Hi Nishant,
I have a master pages contains user control drop down menu.
I want the detail pages to be displayed without refreshing the master page.
Any idea?
Anbu
LikeLike
can anyone help me ??
I want to show a page with several textboxs then in the background I will get some more data and this must be added to the textboxs (or labels), problem is that the additional data can take some time, so I would like to do it asynchronous.
There is a loop (in VB)
i = i + 1 ScriptManager.RegisterStartupScript(Me, Me.GetType, “key” & i.ToString, “changeElementById(‘” & c.ID.ToString & “‘,'” & clientSocketThing(c.ID.ToString) & “‘);”, True)
The problem is that is will refresh the screen if all data is retrieved and not textbox for textbox
LikeLike
Nishant sir your weblog is very good for all the .net developers lik me.
Nishant sir again
Thank you very much
LikeLike
Sir,there is one problem after clicking the “Submit Comment” button on your weblog the name textbox
and email textboxes not get empty.
The same problem i am facing in some of my created websites
LikeLike
Hi ,eDDie ,
are u using the AJAX
LikeLike