Registered members and create your web development database,
Standard HTML forms (FORM elements) allow you to pass and send data information to another page or application to use form elements. In ASP.NET 1.x, the webpage uses the delivery mechanism to submit the page data to the page itself. For ASP.NET 2.0, its functions have expanded and can be allowed to submit across pages. Let's discuss this new feature this week.
Traditional method
To facilitate comparison, I want to spend a minute to review the old ways to transmit data from web pages. HTML's table elements have an Action attribute to specify which resources (so -called resources refer to a webpage, a script, program, etc.) to handle these submitted data. The following code is a sample.
<html>
<head> <Title> SAMPLE HTML FORM </Title> </Head>
<body>
<FORM NAME = "FRMSAMPLE" METHOD = "Post" Action = "Target_url">
<input type = "text" name = "fullname" id = "fullname" />
<input type = "Button" name = "submit" value = "submit" /> />
</form>
</body> </html>
The value entered in the text domain (the name is FullName) will be submitted to the page or program specified by the ACTION attribute of the unit element. For ASP.NET developers, it is extremely uncommon even if they have used a standard HTML form.
When ASP.NET developers are facing the task of passing data information from one web page to another, the room for choice is extremely broad. They include session variables, cookies, querystring variables, Caching cache), and even server.transfer, but ASP.NET 2.0 also provides another choice.
ASP.NET 2.0 provides another way to provide
When designing ASP.NET 2.0, Microsoft recognized the needs of crossing data between web pages. With this consciousness, a postbackurl attribute is added to the Button (button) control of ASP.NT. It allows you to indicate where the form and the above data is delivered when the user is submitted (that is, the URL value specified by the PostBackurl property). Generally speaking, cross -page transmission is the process of using JavaScript in the background.
< %@ page language = "vb" %><! Doctype html public "-// W3C // dtd html 4.0 transitional // en">>
<html> <head>
<Title> Cross Postback Example </Title>
</head> <body>
<FORM ID = "FRMCROSSSSPOSTBACK1" Method = "Post" Runat = "Server">
<asp: label id = "lblname" runat = "server" text = "name:"> </asp: label>
<asp: textbox id = "txtname" runat = "server"> < /asp: textbox> <br />
<asp: label id = "lble-mailaddress" runat = "server" text = "e-mail:"> </asp: label>
<ASP: Textbox ID = "TXTE-MAILADDRESS" Runat = "Server"> < /asp: Textbox> <br />
<asp: Button ID = "Btnsubmit" Runat = "Server" Text = "Submit" Postbackurl = "Crosspostback2.aspx" />
</form> </body> </html>
The ASP.NET page in the ASP.NET page has two text domains (named Name (name) and E-mail (email), and a Button (button) used to submit data. The postback attribute of this submission button is specified as another webpage, so that when the form is submitted, the data can be sent to that page. Note: In this example, the form element is set by the posthod attribute by setting the METHOD attribute to make the post [2] submission method during submission, but this is not necessary, because all Cross Postback (cross -page delivery) uses the post method according to the design.
Use the previous page
When the ASP.NET page is loaded through the calls of cross -page delivery, the Ispostback attribute of the object on it will not be triggered. However, there is a attribute called Previouspage (the previous page) enables you to access and use those who applied cross -page delivery.
Whenever a cross -page request occurs, the Previouspage property of the current page is preserved to reference the pages that are delivered. If the generation of the page does not come from the stimulation of cross -page delivery, or the page is in different program groups, then the Previouspage property will not be initialized.
You can determine whether the page loading is the result of cross -page delivery by checking the Previouspage object. If the value is NULL, it means that it is ordinary load, not the NULL value indicates that the web page comes from cross -page delivery. In addition, the page class also contains a method called ISCROSSSPAGEPOSTBACK, which is specifically used to determine whether the page is the result of cross -page delivery.
Once you are determined, you can access the control on the calling page by the FindControl method of the Previouspage object. The following code is the second page in our example; it is called by the page listed above.
< %@ page language = "vb" %><! Doctype html public "-// W3C // dtd html 4.0 transitional // en">>
<html> <head>
<Title> Cross Postback Example 2 </Title>
</head> <body>
<script language = "vb" runat = "server">
sub page_load ()
if not (page.previouspage is nothing) then)
if not (page.iscrosspagePostback) then
Response.write ("name: + ctype (previouspage.findControl (" txtname "), textbox .text +" <br>)
Response.write ("E-mail:" + Ctype (Previouspage.findControl ("TXTE-MAILADDRSS"), textbox) .text + "<br>")
end if
end if
end sub
</script> </body> </html>
This page determines whether it is called by cross -page delivery. If so, access the values from calling pages through the FindControl method, and convert the control obtained by this method to the Textbox control, and then display the content of their text (text) attributes.
You can convert the entire Previouspage object into a page type that triggers cross -page delivery. This method allows you to access the page of the page and method of the page. Before I give an example of this technology, I need to rewrite the first example to include some global attributes. The following code is the first list of two attributes. These two attributes are used to access the domain value.
< %@ page language = "vb" %><! Doctype html public "-// W3C // dtd html 4.0 transitional // en">>
<html> <head>
<Title> Cross Postback Example </Title>
<script language = "vb" runat = "server">
Public Readonly Property name
get
Return me.txtName.text
end get
End Property
Public ReadOnly Property E-MaiLaddress
get
Return me.txte-mailaddress.text
end get
End Property
</script> </head> <body>
<FORM ID = "FRMCROSSSSPOSTBACK1" Method = "Post" Runat = "Server">
<asp: label id = "lblname" runat = "server" text = "name:"> </asp: label>
<asp: textbox id = "txtname" runat = "server"> < /asp: textbox> <br />
<asp: label id = "lble-mailaddress" runat = "server" text = "e-mail:"> </asp: label>
<ASP: Textbox ID = "TXTE-MAILADDRESS" Runat = "Server"> < /asp: Textbox> <br />
<asp: Button ID = "Btnsubmit" Runat = "Server" Text = "Submit" Postbackurl = "Crosspostback2.aspx" />
</form> </body> </html>
Now that the attributes have been built now, you can easily access them. To be vigilant, the PAGE class Previouspage object must be converted into the correct type, so as to correctly access its attributes. This can be implemented by converting it into a suitable Page class.
<%@ page language = "vb"%>< %@ Reference Page = "~/CrosspostBack1.aspx" %>
<! Doctype html public "-// W3C // dtd html 4.0 transitional // en">>
<html> <head>
<Title> Cross Postback Example 3 </Title>
</head> <body>
<script language = "vb" runat = "server">
sub page_load ()
DIM CPPPAGE As Crosspostback1_ASPX
if not (page.previouspage is nothing) then)
if not (page.iscrosspagePostback) then
if (Page.previouspage.isvalid) Then
cpppage = Ctype (Previouspage, Crosspostback1_aspx)
response.write ("name: + cppppage.name +" <br> ")
Response.write ("E-mail:" + CPPPAGE.E-MAILADDDRESS)
end if
end if
end if
end sub
</script> </body> </html>
Explain this, it defines a reference to the call page on the head head, so that this reference type can be used in the code. Through this reference, the actual VB.NET code uses the CTYPE function to convert the Previouspage object into an appropriate type. After that, those attributes can be used like code demonstration.
The use of the ISVALID method of the PreviousPage object in the above list is reminded here: The ISVALID property on the previous page ensures that you have passed all legal verification and testing before it operates.
Summarize
There are many applications for transmitting data parameters between webs, including maintaining personal user information. The ancestral web solution, like using QueryString and cookies, allows you to point to another page from one page when submission occurs.
ASP.NET 1.1 In addition to providing additional methods, these methods can also be well supported, but ASP.NET 2.0 relies on cross -page delivery, which has made great development in this regard. It makes one web processing data from another webpage simple. When you develop your next ASP.NET 2.0 program, you must make good use of the advantages of this new concept.