How to redirect from one ASP.NET page to another

后端 未结 8 2018
感动是毒
感动是毒 2020-12-19 08:48

How do I redirect from one ASP.NET page to another (\"Webform2.aspx\") by means of a button?

8条回答
  •  长情又很酷
    2020-12-19 09:31

    Personally, if all you're wanting to do is load a new page when a button is clicked, I would do this with client-side script.

    You could use a JS library for this (eg: jQuery), like so:

    jQuery

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

    ASP.NET

    
    

    Or, for a specifically ASP.NETesque way to do it, you can use Button.PostBackUrl as Antonio suggests, which still uses client-side script but means you don't have to write it yourself. The HTML for the button renders as:

    
    

    If you've got other processing to do server-side and you need to redirect afterwards, use Response.Redirect("Webform2.aspx"); in your click handler.

    If that's not working for you, please add some more detail to your question to explain what's happening.

提交回复
热议问题