How to redirect from one ASP.NET page to another

How to redirect from one ASP.NET page to another ("Webform2.aspx") using a button?

+5
source share
8 answers

You can redirect from one page to another using Response.Redirect()

+10
source

set the property PostBackUrl of the button, for example:

button1.PostBackUrl= "Webform2.aspx";
+8
source

, . Response.Redirect, Server.Transfer, Javascript .

Javascript , .    onclick="javascript:window.location.href = Webform2.aspx?id='<%=Request.QueryString["id"]%>' "

Server.Transfer . .. webform2. Webform1.aspx webform2, webform2 req. (Req = 1, Res = 1)

Response.Redirect: webform1 , webform2. URL-, req webform2 (Req = 1 + 1, Res = 1 + 1)

, form.submit(), . html submit.

, , PostBack url.. http://aspdotnetcode.source-of-humor.com/TipsAndTricks/General/CrossPagePostbackAspNetCrossPagePostback.aspx

+2

, , , , script.

JS- (: jQuery), :

JQuery

$(function() {
  $('#<%= button1.ClientID %>').click(function() { 
      window.location.href = "Webform2.aspx"; 
      });
});

ASP.NET

<asp:Button id="button1" runat="server"/>

, ASP.NETesque , Button.PostBackUrl, , script, , . HTML :

<input type="submit" name="button1" value="Button" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;button1&quot;, &quot;&quot;, true, &quot;&quot;, &quot;webform2.aspx&quot;, false, false))" id="button1" />

, , Response.Redirect("Webform2.aspx"); .

, , , .

+2

ASP.NET, :

Response.Redirect("Webform.aspx");

+2

:

protected void Button1_Click(object sender, EventArgs e) {
    Response.Redirect("default2.aspx");
}

, default2.aspx - -,

+1

Response.Redirect(string url) HTTP 302, url. url, URL- .

Server.Transfer(string path) path .. IIS. URL- . , , aspx -.

, . - , " / URL?". Response.Redirect, URL- , URL-. Server.Transfer, URL- , - , , , , - , , URL .

Click ASP.NET Button :

protected void Button1_Click(object sender, EventArgs e)
{
    Response.Redirect("Webform2.aspx");
      // OR
    Server.Transfer("Webform2.aspx");
}
0

Response.Redirect Server.Transfer - -. , .

Response.Redirect URL- URL-, Server.Transfer URL- .

Response.Redirect Server.Transfer , :

Response.Redirect( "UserDetail.aspx" ); Server.Transfer( "UserDetail.aspx" );

, HTTP, . HTTP - , - - . Response.Redirect HTTP- , -, - -. , , "UserRegister.aspx" -, , - "UserDetail.aspx" .

0

All Articles