Home » Asp.netRSS

Is it possible to pass textbox value as a parameter through hyperlink? Thanks

Is it possible to pass textbox value as a parameter through hyperlink, with the press of a button or without? Thanks
 
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
 
       <br />
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button" />

        <asp:HyperLink ID="HyperLink4" runat="server" 
        NavigateUrl="~/ASPInvoiceGrid.aspx?PONumber={0}" Target="_blank">Invoice Details</asp:HyperLink>
        </div>
        


 

 

3 Answers Found

 

Answer 1

Maybe you can use a LonkButton and in the click event you can use Response.Redirect() to redirect to the target page passing the textbox' text value as a querystring param (use UrlEncode on the value). Alternatively use Cross Page Postback and the PreviousPage property. Something you can Google/Bing and consider.

 

Answer 2

Yes, you can do it in multiple ways. One way is to use OnClick event of the button

<script type="text/javascript">
    function setURL() {
        document.getElementById('<%= HyperLink4.ClientID %>').href =
        '~/ASPInvoiceGrid.aspx?PONumber=' + document.getElementById('<%= TextBox1.ClientID %>').value;            
    }
</script>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="setURL(); return false;" />
<asp:HyperLink ID="HyperLink4" runat="server" Target="_blank">Invoice Details</asp:HyperLink> 

That should pass  TextBox value as query parameter. You can also do this in code behind in onclick event. Another unconventional way is doing like this

<% HyperLink4.NavigateUrl="~/ASPInvoiceGrid.aspx?PONumber="+TextBox1.Text; %>
 

Answer 3

Thanks a lot for your help.  

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter