ASP.Net/Response/ReDirect

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Redirect a URL (C#)

   <source lang="csharp">

<%@ Page Language="c#" %> <script Language="c#" runat="server">

 void Page_Load(object source, EventArgs e)
 {
   if (!(IsPostBack))
   { 
     MyButton.Text = "OK";
     MyDropDownList.Items.Add("http://www.nfex.ru");
     MyDropDownList.Items.Add("http://www.nfex.ru");
   }
 }
 public void Click (object sender, EventArgs e)
 {
   Response.Redirect(MyDropDownList.SelectedItem.Text);
 }

</script> <html>

 <body>
   <form id="WebForm1" method="post" runat="server">
     <asp:DropDownList id=MyDropDownList runat="server"/>
     <asp:button id=MyButton runat="server" OnClick="Click" Text=""/>
   </form>
 </body>

</html>

      </source>
   
  


Redirect page to another URL (vb.net)

   <source lang="csharp">

<%@ Page Language="VB" %> <script language="vb" runat="server">

  Sub Page_Load(Source As Object, E as EventArgs)
    If Not IsPostBack Then
      MyButton.Text = "OK"
      MyDropDownList.Items.Add("http://www.nfex.ru")
      MyDropDownList.Items.Add("http://www.nfex.ru")
      MyDropDownList.Items.Add("http://www.nfex.ru")
    End If
  End Sub
  Public Sub Click (ByVal sender As Object, ByVal e As System.EventArgs)
    Response.Redirect(MyDropDownList.SelectedItem.Text)
  End Sub

</script> <html>

 <body>
   <form id="WebForm1" method="post" runat="server">
     <asp:DropDownList id=MyDropDownList runat="server"/>
     <asp:button id=MyButton runat="server" OnClick="Click" Text=""/>
   </form>
 </body>

</html>

      </source>