Two depressing problems were encountered:
When transferring data across pages in Asp.net 2.0, you can use page. previouspage. findcontrol is used to find the control of the Source Page, so as to obtain the corresponding value in the previous page. You can set the postbackurl attribute of the button to specify the target page. Currently, only the control of the postbackurl attribute is botton, linkbotton, imagebotton, so to implement cross-page transfer, only these three controls can be used.
1 ** adds a form and page to the page using masterpage. previouspage is null. therefore, there can only be one form on the master page, that is, one more form, and I have been searching for it for more than two hours. But why is it like this when I have another form? I don't want to, but I will remember it later,
2. Search for the previouspage on the page with the master page. The following is a small example to record the hardships of finding an error this evening.
Masterpage. Master
<% @ Master language = "C #" autoeventwireup = "true" codefile = "masterpage. master. cs" inherits = "masterpage" %>
<! 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> No title page </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Br/>
Above
<Asp: contentplaceholder id = "contentplaceholder1" runat = "server">
</ASP: contentplaceholder>
Below </div>
</Form>
</Body>
</Html>
------- Defa3.3.aspx
<% @ Page Language = "C #" masterpagefile = "~ /Masterpage. Master "autoeventwireup =" true"
Codefile = "default3.aspx. cs" inherits = "default3" Title = "untitled page" %>
<Asp: Content ID = "content1" contentplaceholderid = "contentplaceholder1" runat = "server">
<Asp: linkbutton id = "linkbutton1" runat = "server" postbackurl = "~ /Default4.aspx "> linkbutton </ASP: linkbutton>
<Asp: textbox id = "textbox1" runat = "server" text = "ffff"> </ASP: textbox>
</ASP: content>
----- Defa4.4.aspx
<% @ Page Language = "C #" masterpagefile = "~ /Masterpage. Master "autoeventwireup =" true"
Codefile = "default4.aspx. cs" inherits = "default4" Title = "untitled page" %>
<Asp: Content ID = "content1" contentplaceholderid = "contentplaceholder1" runat = "server">
<Asp: Label id = "label1" runat = "server" text = "label"> </ASP: Label>
</ASP: content>
------- Defa3.3.aspx. CS
Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Public partial class default4: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
If (page. previouspage! = NULL)
{
If (previouspage. iscrosspagepostback)
{
// When a master page exists, you can use this method to find the control in the previous page.
Textbox TB = previouspage. master. findcontrol ("contentplaceholder1"). findcontrol ("textbox1") as textbox;
// If no parent page exists, use the following method to find the control in the previous page
// Textbox TB = This. previouspage. master. findcontrol ("textbox1") as textbox;
This. label1.text = Tb. text;
}
}
}
}