Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass on request query to html hidden variable?

Status
Not open for further replies.

fletchsod

Programmer
Dec 16, 2002
181
I have been learning how to use ASP.NET for 2 years now since I'm so accustom to doing html and php for many years. Here is one part I don't get in ASP.NET. How do you pass on the Request.QueryString("foo") to the html hidden textbox?

--snip--
<INPUT type="hidden" name="htmlVIN" value="<%=Request.QueryString("VIN")%>">
--snip--

Visual Studio won't let me do it this way, so how do you accomplish this? I have a window opener that pass this foo variable from the parent window to this window opener where the request.querystring("foo") pass on the data to the html hidden variable. So, when a submit button is clicked, this data from the hidden variable is then passed on to the next webpage.

Thanks...
FletchSOD
 
You don't need to set hidden fields to pass to the next page. You can set values in the querystring, session, etc and access them on the following pages. If you want to do it your way, set the runat tag on your hidden field to ="server"

<INPUT [red] runat="server"[/red] type="hidden" name="htmlVIN" value="<%=Request.QueryString("VIN")%>">

Then access the value from the code behind.

somevar = me.htmlVin.Text
 
Ah! So that's how it works with the "runat='server'".

If I were to set values in the querystring (from previous page) and access them on the following pages. How would that be done? By adding the "action='foo.aspx?htmlVIN=<%Request.QueryString('VIN')%>" to the <form> tag. Is that what you meant? I didn't try that and I don't think it would work due to the nature of ASP.NET. Correct me if I'm wrong. Know of a good web article that would explain it all?

Whatever happen, I think I can handle it from there. Just trying to understand ASP.NET a little better.

Thanks,
FletchSOD
 
ASP.NET pages post back to themselves. You have to redirect or transfer to another page and use a querystring if you want. Then access the variables from there.
 
if you are used to php (and especially if you worked with a templating engine like smarty or phptemplate) then I would recommend not using the webform postback model. Instead I would use an MVC framework like MonoRail or MS MVC ( requires .net 3.5) they would more closely relate the php model you are used to working with.

a control only needs the runat tag if you want to access the control in the code behind. otherwise you can simply use html tags.

if the control is bound (gridview, repeater, dropdown etc) then when binding you can use
<tag attribute='<%#Eval("")%>' />
note the single quotes and the pound symbol. now to expand on this you can use two way data binding for some controls and use Bind() instead of Eval(). Eval is one way and Bind is two way.
if the control is not data bound (outside a bound control) you can use
<tag attribute='<%=Property%>' />
or
<tag attribute='<%=Function(...)%>' />
again note the single quotes, and this time we use = not #.

there are pros can cons to the webform postback model. if you want a clean SoC and/or automated test for the html then I would highly recommend an MVC framework. otherwise the webform model will work.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Yea, I use php and I liked the way it works as a hypertext processor.

When you mentioned about MVC, so I looked it up on Google and it looked very nice. After a moment of thinking about it, I realize that looking at the inline code (script) with less seperation of scripts is a lot nicer cuz not everyone here at my company will want to spend a lot of time learning new things. So, I'll have to improvise on the webform model somehow.

Thanks for mentioning about MVC...

Thanks...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top