Link to home
Start Free TrialLog in
Avatar of steva
steva

asked on

Setting a HiddenField value from a QueryString

I've declared a hidden field that I'd like to set to the value of a QueryString parameter. The obvious way to do this would be with something like:

<asp:HiddenField ID="hardwareid" runat="server" value=<%Request.QueryString("hardware_id")%> />

but this doesn't work.  I can do it by leaving the value out on the aspx page and setting it on the vb page:

                         hardwareid.Value = Request.QueryString("hardware_id")

But it seems like there ought to be a way to reference the QueryString directly on the aspx page.   Am I missing something?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of guru_sami
guru_sami
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kumaraswamy R

<asp:HiddenField ID="hardwareid" runat="server" value= '<%Request.QueryString("hardware_id")%>' />
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of steva
steva

ASKER

sami:

Tried the <%#..%> in your reference, but it didn't work.
<asp:HiddenField ID="hardware_id" runat="server" Value=<%#Request.QueryString("hardware_id")%>  />

rkworlds:
'<%= Request.QueryString("hardware_id")%>' didn't work for me.  I believe it's assigning the entire string as the value rather than executing the Request.QueryString inside the string.

I notice in your reference that they do what I did to assign the hidden value: assign it on the vb page.

Maybe there is no better way.
thats correct. You cannot access that directly in .aspx.
 The link provided was to  show how you can reference a property from code-behind in .aspx.
So say you had a property set to Request.QueryString("hardware_id") in your code-behind then you can access it like:
value='<%# yourproperty %>'
Avatar of steva

ASKER

Ok.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of steva

ASKER

"but why do you want to do it in the aspx page"

Excellent question!  I just want to learn as much as I can while doing this page.  It seems like there should be a way to do it from the aspx page and if there is I'd like to know what it is.  But I'm getting the impression that there isn't a way, and that's fine.  Now I know.

Thanks to everyone for offering your ideas.  I split the points.