Thursday, 26 January 2023

Page Auto Postback Property

Page Auto Postback Property

A unique JavaScipt method is added by ASP.Net to the produced HTML Page if the web page we build contains one or more Web Controls that are set to use AutoPostBack (each Web Control has its own AutoPostBack attribute). The name of this method is _doPostBack(). It starts a PostBack when Called, which sends information back to the web server. Two more hidden input fields are also added by ASP.NET and are used to send data back to the server. The ID of the Control that raised the event is included here, along with any extra information that may be required. Setting these settings with the correct event data and submitting the form are the responsibilities of the _doPostBack() function. The _doPostBack() function is shown below:-

E.g.: -if(Page.IsPostBack==True)

{

// Do processing

}

OR

if(!Page.IsPostBack)

{

// Do Processing

 }

OR

<script runat="server">

Sub Change(obj As Object, e As EventArgs)

  Response.Write("You selected " & rb1.SelectedItem.Text)

End Sub

</script>

 

<form runat=server>

<asp:RadioButtonList id="rb1" AutoPostBack="True"

runat="server" OnSelectedIndexChanged="Change">

  <asp:ListItem Text="Item 1" />

  <asp:ListItem Text="Item 2" />

</asp:RadioButtonList>

</form>


ASP.NET generates the _doPostBack() function automatically, provided at least one control on the page uses automatic post backs. Any Control that has its AutoPostBack Property set to true is connected to the _doPostBack() function using the onclick or onchange attributes. These attributes indicate what action should Browser take in response to the Client-Side javascript events onclick and onchange. In other words, ASP.Net automatically changes a client-side javascript event into a server-side ASP.Net event, using the _doPostBack() function as an intermediary.

https://www.youtube.com/channel/UCKLRUr6U5OFeu7FLOpQ-FSw/videos

0 comments

Post a Comment