add querystring to a postbackurl property of asp:button
-
19-08-2019 - |
Question
I've got a textbox and a button on a form on default.aspx and in my DownloadHandler.ashx I am getting the value I need from HttpContext.Request.Form("txtURI"):
<asp:TextBox ID="txtURI"
AutoPostBack="true"
runat="server"></asp:TextBox>
<asp:Button ID="DownloadButton"
PostBackUrl="~/DownloadHandler.ashx"
runat="server"
Text="Download"/>
I would like to change it so that the value typed into the textbox gets passed to the DownloadHandler.ashx as a querystring (instead of picking it out of the Request.Form).
What is the best way to accomplish that?
Solution
I think you answered your own question. I believe you're going to have to pick it up on the request and redirect.
Actually, the more I think about it. You could add a OnClientClick, calling a javascript function which would grab the value from the field and do the submit there. I would just do it serverside however.
OTHER TIPS
You can also use command parameter name and command parameter value in your button and that way pass value you need.
<asp:Button ID="DownloadButton"
CommandName="Download"
CommandArgument="whatever_argument_or_value" OnCommand="Download_Command"
runat="server" Text="Download"
/>