views:

2298

answers:

2

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?

+1  A: 

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.

madcolor
Not sure what you mean "pick it up on the request". How to append a proper querystring to the PostBackURL?
John Galt
The page would post back to itself (default behavior), then in your code-behind, you would have to grab the txtURI.Text value, append it to whatever URL you want to post to and either do a Response.Redirect or a Server.Transfer(). Depending on what you're going for.
madcolor
A: 

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"
/>
Dmitris
Will this put the command in the Querystring?
madcolor
No, but will pass command name and parameter to the function Download_Command.I know my answer is not what you asked, it just another way to put parameter in function.
Dmitris
I just realized you asked for something absolutely different, sorry.
Dmitris