Surya
Surya

Reputation: 157

How to Pass Text Box Value to Query String Using HyperLink Field In Client Side Using Asp.Net

Iam developing application in asp.net c#, in that i have a requirement to pass text box value through query string without using server side code, in that iam trying some code below, but its not working for me.

<asp:HyperLink ID="hlnkHistory" runat="server" Text="History" ForeColor="Green" ImageUrl="~/images/History2.png" Font-Bold="true" Target="_blank" NavigateUrl="~/WebFormReports/History.aspx?SerialNo=<%#Eval('txtSerialNo.ClientID')%>" ToolTip="View History"></asp:HyperLink>

When iam assign value directly like the below code its working fine.

<asp:HyperLink ID="hlnkHistory" runat="server" Text="History" ForeColor="Green" ImageUrl="~/images/History2.png" Font-Bold="true" Target="_blank" NavigateUrl="~/WebFormReports/History.aspx?SerialNo=1" ToolTip="View History"></asp:HyperLink>

Note: i need not server side code to pass value like

protected void lnkNavigate_Click(object sender, EventsArgs e)
{ 
    Response.Redirect("MyLocation.aspx?value=" + myTextBox.Text, false);     
}

if it is not possible means please tell me is there any another option to pass text box value to query string like a href & link button

any help would be appreciated.. thanks in advance..

Upvotes: 0

Views: 1977

Answers (1)

VDWWD
VDWWD

Reputation: 35524

If you want to still use the asp:HyperLink then you can use this snippet.

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:HyperLink ID="hlnkHistory" runat="server" Text="History" ForeColor="Green" ImageUrl="~/images/History2.png" Font-Bold="true" Target="_blank" NavigateUrl="~/WebFormReports/History.aspx?SerialNo=" ToolTip="View History" onclick="setHyperlink()"></asp:HyperLink>

<script type="text/javascript">
    function setHyperlink() {
        var value_hyperlink = $("#<%=hlnkHistory.ClientID %>").attr("href");
        var value_textbox = $("#<%=TextBox1.ClientID %>").val();
        $("#<%=hlnkHistory.ClientID %>").attr("href", value_hyperlink + value_textbox);
    }
</script>

If you don't need that hyperlink, you can use a somewhat simpler javascript function.

location.href = "~/WebFormReports/History.aspx?SerialNo=" + $("#<%=TextBox1.ClientID %>").val();

Upvotes: 1

Related Questions