ASP.Net: Response.Redirect

Not all page navigation scenarios are initiated through hyperlinks on the client. Client-side page redirects or navigations can also be initiated from the server by an ASP.NET page developer by calling the Response.Redirect(url) method. This is typically done when server-side validation is required on some client input before the navigation actually takes place.

The following sample demonstrates how to use the Response.Redirect method to pass parameters to another target page. It also demonstrates how to easily get access to these parameters from the target page.


<html>
<script language="VB" runat="server">
Sub EnterBtn_Click(Sender As Object, E As EventArgs)
' Navigate to a new page (passing name as a querystring argument) if
' user has entered a valid name value in the <asp:textbox>
If Not (Name.Text = "") Response.Redirect("Controls_NavigationTarget_vb.aspx?name=" & System.Web.HttpUtility.UrlEncode(Name.Text))
Else
Message.Text = "Hey! Please enter your name in the textbox!"
End If
End Sub
</script>
<body>
<h3><font face="Verdana">Performing Page Navigation (Scenario 2)</font></h3>
<p>
This sample demonstrates how to navigate to a new page from within a
click event,
passing a
value as a querystring argument (validating first that the a legal
textbox value has been specified).
<p>
<hr>
<form action="controls6.aspx" runat=server>
<font face="Verdana">
Please enter your name: <asp:textbox id="Name" runat=server/>
<asp:button text="Enter" Onclick="EnterBtn_Click" runat=server/>
<p>
<asp:label id="Message" forecolor="red" font-bold="true" runat=server/>
</font>
</form>
</body>
</html>

That’s brilliant!

Read Users' Comments (0)

0 Response to "ASP.Net: Response.Redirect"

Post a Comment