Asp Net Disable to Display the Webpage Again Postback
PostBack is the name given to the process of submitting an ASP.Net page to the server for processing. PostBack is done if certain credentials of the page are to be checked against some sources (such as verification of username and countersign using database). This is something that a client machine is not able to accomplish and thus these details have to be 'posted back' to the server.
What is AutoPostBack Holding in ASP.NET
If we create a web Page, which consists of one or more Web Controls that are configured to use AutoPostBack (Every Web controls will have their own AutoPostBack belongings), the ASP.Net adds a special JavaScipt function to the rendered HTML Page. This part is named _doPostBack() . When Called, it triggers a PostBack, sending data dorsum to the web Server.
ASP.Net likewise adds two additional hidden input fields that are used to pass information back to the server. This information consists of ID of the Control that raised the issue and any additional data if needed. These fields will empty initially as shown below,
- < input blazon = "subconscious" name = "__EVENTTARGET" id = "__EVENTTARGET" value = "" />
- < input type = "hidden" name = "__EVENTARGUMENT" id = "__EVENTARGUMENT" value = "" />
The _doPostBack() function has the responsibility for setting these values with the appropriate information almost the event and the submitting the class. The _doPostBack() role is shown below:
- <script language= "text/javascript" >
- function __doPostBack(eventTarget, eventArgument) {
- if (!theForm.onsubmit || (theForm.onsubmit() != false )) {
- theForm.__EVENTTARGET.value = eventTarget;
- theForm.__EVENTARGUMENT.value = eventArgument;
- theForm.submit();
- }
- </script>
ASP.Cyberspace generates the _doPostBack() office automatically, provided at least ane control on the page uses automated postbacks.
Whatever Control that has its AutoPostBack Property gear up to true is connected to the _doPostBack() part using the onclick or onchange attributes. These attributes point what action should Browser have in response to the Client-Side javascript events onclick and onchange.
In other words, ASP.Internet automatically changes a client-side javascript event into a server-side ASP.Net event, using the _doPostBack() function equally an intermediary.
Life Cycle of a Web Page:
To work with the ASP.Net Spider web Controls events, we need a solid understanding of the web page life cycle. The post-obit actions volition be taken place when a user changes a control that has the AutoPostBack property ready to truthful :
- On the customer side, the JavaScript _doPostBack function is invoked, and the page is resubmitted to the server.
- ASP.NET re-creates the Page object using the .aspx file.
- ASP.Internet retrieves state information from the subconscious view state field and updates the controls accordingly.
- The Page.Load event is fired.
- The appropriate change event is fired for the control. (If more than one control has been changed, the social club of alter events is undetermined.)
- The Page.PreRender event fires, and the page is rendered (transformed from a set of objects to an HTML page).
- Finally, the Page.Unload event is fired.
- The new page is sent to the client.
To lookout these events in action, we can create a elementary event tracker awarding. All this application does is write a new entry to a list command every fourth dimension one of the events it'south monitoring occurs. This allows you to meet the club in which events are triggered.
Event Tracker Web Page
I have shown Markup codes and C# Codes below to make this works,
EventTracker.aspx
- < %@ Page Linguistic communication = "C#" AutoEventWireup = "true" CodeFile = "EventTracker.aspx.cs" Inherits = "EventTracker" % >
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- < html xmlns = "http://www.w3.org/1999/xhtml" >
- < head runat = "server" >
- < title > Untitled Folio </ title >
- </ head >
- < body >
- < form id = "form1" runat = "server" >
- < div >
- < h1 > Controls being monitored for change events: </ h1 >
- < asp:TextBox ID = "txt" runat = "server" AutoPostBack = "true"
- OnTextChanged = "CtrlChanged" />
- < br /> < br />
- < asp:CheckBox ID = "chk" runat = "server" AutoPostBack = "true"
- OnCheckedChanged = "CtrlChanged" />
- < br /> < br />
- < asp:RadioButton ID = "opt1" runat = "server" GroupName = "Sample"
- AutoPostBack = "true" OnCheckedChanged = "CtrlChanged" />
- < asp:RadioButton ID = "opt2" runat = "server" GroupName = "Sample"
- AutoPostBack = "true" OnCheckedChanged = "CtrlChanged" />
- < h1 > List of events: </ h1 >
- < asp:ListBox ID = "lstEvents" runat = "server" Width = "355px"
- Elevation = "150px" /> < br />
- < br /> < br /> < br />
- </ div >
- </ form >
- </ body >
- </ html >
EventTrakcer.aspx.cs
- using System;
- using System.Collections;
- using Arrangement.Configuration;
- using System.Data;
- using System.Web;
- using Organisation.Web.Security;
- using Organisation.Web.UI;
- using System.Web.UI.HtmlControls;
- using Organisation.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- public partial course EventTracker : Arrangement.Spider web.UI.Page
- {
- protected void Page_Load( object sender, EventArgs due east)
- {
- Log("<< Page_Load >>" );
- }
- protected void Page_PreRender( object sender, EventArgs e)
- {
- Log("Page_PreRender" );
- }
- protected void CtrlChanged(Object sender, EventArgs e)
- {
- string ctrlName = ((Control)sender).ID;
- Log(ctrlName +" Changed" );
- }
- individual void Log( cord entry)
- {
- lstEvents.Items.Add together(entry);
- lstEvents.SelectedIndex = lstEvents.Items.Count - one;
- }
- }
What the above Code does
The code writes to the ListBox using a private Log() method. The Log() method adds the text and automatically scrolls to the bottom of the listing each time a new entry is added, thereby ensuring that the most contempo entries remain visible.
All the change events are handled by the same method, CtrlChanged().If you look carefully at the .aspx file, you'll notice see that each input command connects its monitored upshot to the CtrlChanged() method. The event handling code in the CtrlChanged() method uses the source parameter to find out what control sent the result, and information technology incorporates that data in the log string.
The folio includes event handlers for the Page.Load and Page.PreRender events. As with all page events, these event handlers are connected by method name. That means to add the event handler for the Page.PreRender outcome, you lot simply need to add together a method named Page_PreRender(), like the one shown hither.
Thanks....
buchanansheyetterly.blogspot.com
Source: https://www.c-sharpcorner.com/uploadfile/2f73dd/what-is-postback-in-Asp-Net/
0 Response to "Asp Net Disable to Display the Webpage Again Postback"
Post a Comment