CBA

ASP.NET 2.0中的Web和HTML服务器控件(3)

2019-09-13 20:28:13来源:励志吧0次阅读

执行页面导航(第一种情况)

在实际的Web应用程序中,多个页面之间的导航是常见的。下面的例子演示了如何使用<asp:hyperlink runat=server>控件导航到另外一个页面(同时传递了自定义的查询字符串参数)。接着这个例子演示了如何轻易地在目标页面上得到这些查询字符串参数。

<html>

<script language="VB" runat="server">

Sub Page_Load(Sender As Object, E As EventArgs)

Dim RandomGenerator As Random

RandomGenerator = New Random(DateTime.Now.Millisecond)

Dim RandomNum As Integer

RandomNum = RandomGenerator.Next(0, 3)

Select RandomNum

Case 0:

Name.Text = "Scott"

Case 1:

Name.Text = "Fred"

Case 2:

Name.Text = "Adam"

End Select

AnchorLink.NavigateUrl = "controls_navigationtarget_vb.aspx?name=" & System.Web.HttpUtility.UrlEncode(Name.Text)

End Sub

</script>

<body>

<h3><font face="Verdana">Performing Page Navigation (Scenario 1)</font></h3>

<p>

This sample demonstrates how to generate a HTML Anchor tag that will cause the client to

navigate to a new page when he/she clicks it within the browser.

<p>

<hr>

<p>

<asp:hyperlink id="AnchorLink" font-size=24 runat=server>

Hi <asp:label id="Name" runat=server/> please click this link!

</asp:hyperlink>

</body>

</html>

执行页面导航(第二种情况)

并非所有的页面导航都由客户端的超级链接发起。ASP.NET页面开发者调用Response.Redirect(url)方法也可以发起客户端页面的重定向或导航。这种情况典型发生在真正进行导航之前,服务器端需要验证客户端的输入信息的时候。

下面的例子演示了如何使用Response.Redirect方法把参数传递到另外一个目标页面。它还演示了如何在目标页面上简单地获取这些参数。

<html>

<script language="VB" runat="server">

Sub EnterBtn_Click(Sender As Object, E As EventArgs)

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 <asp:button> click event, passing a <asp:textbox> 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> 查看本文来源

宝宝经常发烧
婴儿退烧物理降温方法
宝宝脸有点黄怎么回事
小孩夜里咳嗽
分享到: