Very simple question.

B

Badass Scotsman

Hello,

I have some "runat server" form boxes on the page, for example:

<asp:textbox class="textbox" runat="server" type="text" name="Email"
maxlength="200" id="Email" value="" />

How can I prepopulate this field from the QueryString?

The following creates an error:
<asp:textbox class="textbox" runat="server" type="text" name="Email"
maxlength="200" id="Email" value="<%=Request.QueryString("Email")%>" />

I tried Google but was not really sure how to find the answer.

Regards,

Gary.
 
K

Karl Seguin [MVP]

In 1.x, you'd go into your codebehind and do:

protected Email as TextBox

sub page_Load(..)
Email.Text = Request.QueryString("Email")
end sub


in 2.0 you could omit the 1st line..

Karl
 
G

Guest

Well, typically you would want to keep your markup separate from your code by
using a code-behind approach. And, using this approach it would alleviate
much of your pain.

So, you would be able to do a very simple line of code in the code behind,
perhaps in the Page_Load even handler such as:

Email.Text = Request.QueryString["Email"];
 
R

rjl444

in code behind read the paramater into a mehod variable , then in the
asp page:
codebehind:
public String email = Request.QueryString["Email"];

then in asp page:

value="<%=email%>"
 
B

Badass Scotsman

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:[email protected]...
In 1.x, you'd go into your codebehind and do:

protected Email as TextBox

sub page_Load(..)
Email.Text = Request.QueryString("Email")
end sub


in 2.0 you could omit the 1st line..

Karl



Thank you kindly, this worked a treat. Sorry to be a nuisence, could you I
would like to apply the exact same principle to this control:

<asp:DropDownList ID="TypeOfParrot" Runat="server" name="TypeOfParrot"
class="textbox">
<asp:ListItem Value="">Please Select</asp:ListItem>
<asp:ListItem Value="Cockatoo">Cockatoo</asp:ListItem>
<asp:ListItem Value="MaCaw">MaCaw</asp:ListItem>
<asp:ListItem Value="African Grey">African Grey</asp:ListItem>
</asp:DropDownList>

So if the Querystring in the URL had domain.com?Parrot=Cockatoo , the
DropDownList above would default to this value both visually and behind the
scenes.

Any help again appreciated!!

Regards,

Gary.
PS - Really need to learn .net, and fast.
 
M

MSDN

your quotes are confusing

value="<%=Request.QueryString("Email")%>"
you need to use single quotes or double quotes
value='<%=Request.QueryString("Email")%>'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top