Problem of cross-page value passing postbackurl

Source: Internet
Author: User

Default. aspx has only one button and one text

Protected void button#click (Object sender, eventargs E)
{
Button1.postbackurl = "~ /Default2.aspx ";
}

Default2.aspx contains a text

If (previouspage! = NULL)
{
Textbox1.text = (previouspage. findcontrol ("textbox1") as textbox). text;
}

-----------------------------------------------------
Question: In default. aspx, click button1 twice to enter default2.aspx.

Solution:

Protected void button#click (Object sender, eventargs E)
{
Button1.postbackurl = "~ /Default2.aspx ";
}
The purpose of this Code is to set the URL address "~ /Default2.aspx "is assigned to the postbackurl attribute,
When you click it for the first time, it only serves as a value assignment,
During the second click, the button executes the postbackurl attribute mechanism to redirect the page to the page you want to jump.

You can directly assign the URL address to the postbackurl attribute at the front-end.

Method 1: HTML code
   <asp:Button ID="Button1" runat="server" PostBackUrl="~/Default2.aspx" Text="baidu" />
Or,
Method 2: what is written in the background
C # code
      protected void Button1_Click(object sender, EventArgs e){this.Button1.PostBackUrl ="~/Default2.aspxButton1_Click(this,e);}
Method 3: You can also put this sentence button1.postbackurl = "~ /Default2.aspx "; written in page_load

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.