Hi

I am trying to pass value of textbox from Default.aspx to Default2.aspx through a link. I am using VS2008.
Here is my Default.aspx code

<body>
    <form id="form1" method="get" runat="server">
    
        <asp:Label ID="Label2" runat="server" Text="Name"></asp:Label>

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

        <br />
        <br />
        <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>

        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <br />
<br />
        [B]<a href ="Default2.aspx?&name=<% =TextBox1.Text%>" >Link</a>[/B] </form>
</body>
</html>

And I am trying to use this code to display the value on Default2.aspx

<body>
    <form id="form1" runat="server">
    <center>
      <%
      string Name = Request.QueryString["name"];
      %>
      <h1>Happy Birthday [B]<% Response.Write(Name); %[/B]></h1>
      <h3>May the next

      years be as good!</h3>
    </center>

    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </form>

</body>

Can any one help me displaying the name of user on Default.aspx.

Thanx to all in advance

Regards

Recommended Answers

All 4 Replies

You can't do this using hyperlink because value of TextBox1.Text property is empty when a page is requested first time. Use LinkButton/Button/Image button and set PostBackUrl property.

...
<asp:Label ID="Label2" runat="server" Text="Name"></asp:Label>

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

        <br />
        <br />
        <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>

        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <br />
<br />
         
    <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/Default2.aspx">LinkButton</asp:LinkButton>
....
...
<center>
      <%
      string Name = Request["TextBox1"];
      %>
      <h1>Happy Birthday <% Response.Write(Name); %></h1>
      <h3>May the next

      years be as good!</h3>
    </center>

    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
....

That was a good article i think you got your answer from that thread .!!
if not then explain your requirement again.
Regards
Shakeb Khan

Use javascript function OnClick on Link that take value from Text box And also redirect to the page
use this idea or any other id of creating java script function.
I have not tried yet but i hope help full for you

function OnClickLink()
{
var txt= Document.getElementbyid(<%ControlID%>).text
var url="yourpage.aspx?Name=txt

/////
//////
logic
////
///
return url
}

With Regards
Shakeb Khan

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.