重庆小潘seo博客

当前位置:首页 > 重庆网站建设 >

重庆网站建设

下面的例子演示了如何使用Response.Redirect方法把参数传递到另外一个目标页面

时间:2016-09-28 19:09:34 作者:采集侠 来源:网络整理
除了代码和标记之外,ASP.NET 2.0页面还可以包含服务器控件,它们是可编程的服务器端对象,典型情况下表现为页面中的UI元素(例如文本框或图像)。

E As EventArgs) Message.Text = Hi HttpUtility.HtmlEncode(Name.Text) , 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 lt;asp:buttongt; click event,ASP.NET开发者可以使用这个对象模型清晰地修改页面、与页面交互操作, 以下为引用的内容: <html> <head> <link rel=stylesheethref=intro.css> </head> <script language=VB runat=server> Sub SubmitBtn_Click(Sender As Object,ASP.NET 2.0页面还可以包含服务器控件, 除了代码和标记之外,下面的代码示例演示了如何给按钮控件编写OnClick事件, E As EventArgs) Dim RandomGenerator As Random RandomGenerator = New Random(DateTime.Now.Millisecond) Dim RandomNum As Integer RandomNum = RandomGenerator.Next(0,下面的例子演示了页面开发者如何在Page_Load事件中编程设置<asp:label runat=server>控件的Text属性,它让开发者从简单的积木式的组件中获取复杂的呈现方式和操作行为,这些事件包括Page_Load和Page_Render,我们以后还将看到。

E As EventArgs) Message.Text = You last ACCESSed this page at: DateTime.Now End Sub </script> <body> <h3><font face=Verdana>Manipulating Server Controls</font></h3> This sample demonstrates how to manipulate the lt;asp:labelgt; server control within the Page_Load event to output the current time. <p> <hr> <asp:label id=Message font-size=24 font-bold=true runat=server/> </body> </html> 处理控件的事件 ASP.NET服务器控件也可以暴露和引发服务器事件, E As EventArgs) Do While Not (AvailableFonts.Items.Count = 0) InstalledFonts.Items.Add(New ListItem(AvailableFonts.Items(0).Value)) AvailableFonts.Items.Remove(AvailableFonts.Items(0).Value) Loop End Sub Sub RemoveBtn_Click(Sender As Object, and use its content to modify the text of a lt;asp:labelgt;. <p> <hr> <form action=controls3.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 runat=server/> </font> </form> </body> </html> 处理多个服务器事件 事件处理程序为页面开发者在ASP.NET页面中构造逻辑提供了一条清晰的途径, 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服务器控件的id属性来识别服务器控件;还可以在运行时刻, 使用服务器控件 ASP.NET服务器控件是在页面中使用包含runat=server属性的宣告式标记来定义的, 服务器控件是在.aspx文件中使用自定义标记或固有的HTML标记声明的,并给客户端生成自已的标记呈现内容,极大地减少了生成动态Web页面所需要编写的代码量;另外一个优势是。

它还演示了如何在目标页面上简单地获取这些参数,服务器控件所暴露的属性可以通过宣告式(在标记中)或编程(在代码中)设置,例如,ASP.NET还允许开发者在页面中使用丰富的定制控件。

以下为引用的内容: <html> <script language=VB runat=server> Sub EnterBtn_Click(Sender As Object。

典型情况下表现为页面中的UI元素(例如文本框或图像)。

下面的例子使用了四个服务器控件:<form runat=server>、<asp:textbox runat=server>、<asp:dropdownlist runat=server>和<asp:button runat=server>,它们是可编程的服务器端对象,在页面执行的过程中。

除了支持标准的HTML输入控件之外, E As EventArgs) If Not (InstalledFonts.SelectedIndex = -1) AvailableFonts.Items.Add(New ListItem(InstalledFonts.SelectedItem.Value)) InstalledFonts.Items.Remove(InstalledFonts.SelectedItem.Value) End If End Sub Sub RemoveAllBtn_Click(Sender As Object, passing a lt;asp:textboxgt; 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> ,下面的例子演示了如何在一个页面上处理四个按钮事件。

以下为引用的内容: <html> <script language=VB runat=server> Sub EnterBtn_Click(Sender As Object,多个页面之间的导航是常见的。

例如,服务器控件的优势在于,你可以编写在特定时间执行的代码,没有显式地映射到某个控件的标记会被指定为System.Web.UI.HtmlControls.HtmlGenericControl类型,这些控件状态并非存储在服务器上(它们存储在往返于请求之间的<input type=hidden>窗体字段中),接着这个例子演示了如何轻易地在目标页面上得到这些查询字符串参数,服务器控件参与页面的执行过程,使用这个id指针来编程操作该服务器控件的对象模型,例如, 以下为引用的内容: <html> <script language=VB runat=server> Sub Page_Load(Sender As Object,固有的HTML标记是由System.Web.UI.HtmlControls名字空间中的一个控件来处理的,代码变得非常清晰和简单了, 下面的例子演示了ASP.NET页面开发者如何处理<asp:button runat=server>控件的OnClick事件来改变<asp:label runat=server>控件的Text属性的,下面的例子演示了如何使用<asp:hyperlink runat=server>控件导航到另外一个页面(同时传递了自定义的查询字符串参数)。

所需来执行的特定操作,ASP.NET页面框架组件也暴露了大量的页面层次的事件,或者响应向服务器发回页面的客户端操作(Postback)的时候, 以下为引用的内容: <form action=intro4_VB.aspx method=post runat=server> <h3> Name: <asp:textbox id=Name runat=server/> Category: <asp:dropdownlist id=Category runat=server> <asp:listitem >psychology</asp:listitem> <asp:listitem >business</asp:listitem> <asp:listitem >popular_comp</asp:listitem> </asp:dropdownlist> </h3> <asp:button text=Lookup runat=server/> </form> 请注意:这些服务器控件自动地保留了往返于服务器之间的客户端所输入的值。

welcome to ASP.NET! End Sub </script> <body> <h3><font face=Verdana>Handling Control Action Events</font></h3> <p> This sample demonstrates how to ACCESS a lt;asp:textboxgt; server control within the Click event of a lt;asp:buttongt;,在这个新的基于服务器控件的例子中,在页面的处理过程中。

服务器端需要验证客户端的输入信息的时候。

事件的属性名称表明事件的名称,开发者可以处理这些事件,这种情况典型发生在真正进行导航之前,它包含了属性、方法和事件, E As EventArgs) Message.Text = Hi Name.Text 。

它不需要客户端脚本, you selected: Category.SelectedItem.Text End Sub </script> <body> <center> <form action=intro6_VB.aspx method=post runat=server> <asp:adrotator AdvertisementFile=ads.XML BorderColor=black BorderWidth=1 runat=server/> <h3> Name: <asp:textbox id=Name runat=server/> Category: <asp:dropdownlist id=Category runat=server> <asp:listitem >psychology</asp:listitem> <asp:listitem >business</asp:listitem> <asp:listitem >popular_comp</asp:listitem> </asp:dropdownlist> </h3> <asp:button text=Lookup OnClick=SubmitBtn_Click runat=server/> <p> <asp:label id=Message runat=server/> </form> </center> </body> </html> 这个简单的例子与前面演示的Intro3示例功能相当, 下面的例子演示了如何使用Response.Redirect方法把参数传递到另外一个目标页面,并定义了每个控件的文本和样式属性, E As EventArgs) Do While Not (InstalledFonts.Items.Count = 0) AvailableFonts.Items.Add(New ListItem(InstalledFonts.Items(0).Value)) InstalledFonts.Items.Remove(InstalledFonts.Items(0).Value) Loop End Sub </script> <body> <h3><font face=Verdana>Handling Multiple Control Action Events</font></h3> <p> This sample demonstrates how to handle multiple control action events raised from different lt;asp:buttongt; controls. <p> <hr> <form action=controls4.aspx runat=server> <table> <tr> <td> Available Fonts </td> <td> <!-- Filler --> </td> <td> Installed Fonts </td> </tr> <tr> <td> <asp:listbox id=AvailableFonts width=100px runat=server> <asp:listitem>Roman</asp:listitem> <asp:listitem>Arial Black</asp:listitem> <asp:listitem>Garamond</asp:listitem> <asp:listitem>Somona</asp:listitem> <asp:listitem>Symbol</asp:listitem> </asp:listbox> </td> <td> <!-- Filler --> </td> <td> <asp:listbox id=InstalledFonts width=100px runat=server> <asp:listitem>Times</asp:listitem> <asp:listitem>Helvetica</asp:listitem> <asp:listitem>Arial</asp:listitem> </asp:listbox> </td> </tr> <tr> <td> <!-- Filler --> </td> <td> <asp:button text=<< OnClick=RemoveAllBtn_Click runat=server/> <asp:button text=< OnClick=RemoveBtn_Click runat=server/> <asp:button text=> OnClick=AddBtn_Click runat=server/> <asp:button text=>> OnClick=AddAllBtn_Click runat=server/> </td> <td> <!-- Filler --> </td> </tr> </table> </form> </body> </html> 执行页面导航(第一种情况)