.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Pass variable from one page to other

Posted By:satyapriyanayak       Posted Date: April 01, 2013    Points: 25    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

Pass variable from one page to other
 

FirstForm.aspx code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="FirstForm.aspx.vb" Inherits="FirstForm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Font-Bold="True" Text="First Name"
            Width="160px"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server" Width="200px"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
            ControlToValidate="TextBox1" ErrorMessage="Name Required"></asp:RequiredFieldValidator>
        <br />
        <asp:Label ID="Label2" runat="server" Font-Bold="True" Text="Email"
            Width="160px"></asp:Label>
        <asp:TextBox ID="TextBox2" runat="server" Width="200px"></asp:TextBox>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
            ControlToValidate="TextBox2" ErrorMessage="Invalid Email"
            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
            ControlToValidate="TextBox2" ErrorMessage="Email Required"></asp:RequiredFieldValidator>
        <br />
        <asp:Label ID="Label3" runat="server" Font-Bold="True" Text="Mobile No"
            Width="160px"></asp:Label>
        <asp:TextBox ID="TextBox3" runat="server" Width="200px"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
            ControlToValidate="TextBox3" ErrorMessage="Mobile No. Required"></asp:RequiredFieldValidator>
        <br />
        <asp:Label ID="Label4" runat="server" Font-Bold="True" Text="Country"
            Width="160px"></asp:Label>
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem>India</asp:ListItem>
            <asp:ListItem>usa</asp:ListItem>
            <asp:ListItem>uk</asp:ListItem>
            <asp:ListItem>Nepal</asp:ListItem>
            <asp:ListItem>Srilanka</asp:ListItem>
            <asp:ListItem>Australia</asp:ListItem>
            <asp:ListItem>Germany</asp:ListItem>
        </asp:DropDownList>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
            ControlToValidate="DropDownList1" ErrorMessage="Country Required"></asp:RequiredFieldValidator>
    </div>
    <asp:Button ID="Button1" runat="server" Font-Bold="True"
        onclick="Button1_Click" Text="Pass variables to second form" />
    </form>
</body>
</html>

FirstForm.aspx.vb code

Partial Class FirstForm
    Inherits System.Web.UI.Page
    Dim url As String
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        url = "SecondForm.aspx?name=" & TextBox1.Text & "&email=" & TextBox2.Text & "&mobileno=" & TextBox3.Text & " &country=" & DropDownList1.SelectedItem.Text
        Response.Redirect(url)
    End Sub
End Class

SecondForm.aspx code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="SecondForm.aspx.vb" Inherits="SecondForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Font-Bold="True" Text=" Email:*"
            Width="160px"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server" Width="200px"></asp:TextBox>
        <br />
       
        <asp:Label ID="Label4" runat="server" Font-Bold="True" Text="First Name:*"
            Width="160px"></asp:Label>
        <asp:TextBox ID="TextBox4" runat="server" Width="200px"></asp:TextBox>
        <br />
        
        <asp:Label ID="Label6" runat="server" Font-Bold="True" Text="Mobile Number: *"
            Width="160px"></asp:Label>
        <asp:TextBox ID="TextBox6" runat="server" Width="200px"></asp:TextBox>
        <br />
        <asp:Label ID="Label7" runat="server" Font-Bold="True"
            Text="You have selected: *" Width="160px"></asp:Label>
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>
        <br />
    </div>
    <br />
    </form>
    </body>
</html>

SecondForm.aspx.vb code

Partial Class SecondForm
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TextBox4.Text = Request.QueryString("name")
        TextBox1.Text = Request.QueryString("email")
        TextBox6.Text = Request.QueryString("mobileno")
        DropDownList1.Items.Add(Request.QueryString("country"))
    End Sub
End Class



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend