input from a web form

P

Pierre

Hi,

I try to get some input from a web form using the POST method, but
somehow with my code the variables are never empty.

My form:
<form class="specs" method="post" name="Form" action="WebForm1.aspx">
<div>Login: <input class="login" type="text" name="Login"></div>
<div>Password: <input class="login" type="password"
name="Password"></div>
<input class="login" type="submit" value="Submit">
</form>

My C# code:
private void Page_Load(object sender, System.EventArgs e)
{
Hashtable xsltParams = new Hashtable();
Hashtable xsltObjects = new Hashtable();

String user;
if(Request.Form["Login"]=="")
{
Session["user"]=Request["Login"];
xsltParams.Add("login",Request.Form["Login"]);
}
else{
xsltParams.Add("login","guest");
}

}

Thx in advance for yur advices, answers.

Regards,
Pierre
 
M

Mark Rae

I try to get some input from a web form using the POST method, but
somehow with my code the variables are never empty.

1) Stop and start the webservices (pop a command window and run iisreset) -
what are the values when the page opens for the very first time after that?

2) Currently your Page_Load code will run every time the page loads, not
just when the user clicks the submit button. You need to run it only when a
postback occurs e.g.

private void Page_Load(object sender, System.EventArgs e)
{
if (Page.IsPostBack == false)
{
// maybe clear out the textboxes
}
else
{
// run your login code
}
}
 
P

Pierre

ok thx that works now.

Just a new problem: if I have the code below, it seems I dun even read
the variable anymore (like I would not postback when I click on
submit).

if (Page.IsPostBack == false)
{
xsltParams.Add("login","Guest");
}
else
{
if(Request["Login"]=="")
{
xsltParams.Add("login","Guest");
}
else
{
String login=Request["Login"];
Session["login"]=login;
xsltParams.Add("login",login);
}
}
 
M

Mark Rae

ok thx that works now.

Just a new problem: if I have the code below, it seems I dun even read
the variable anymore (like I would not postback when I click on
submit).

So put a break point in the if(Page.IsPostBack == false) line and see what
is happening...
 
P

Pierre

yeah that's what I thought, when I click on submit, it all comes back
to

Page.IsPostBack == false

same thing when I click on a link like ?nav=home

I really don't know how to make this postback working.
 

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