N
Nate Hekman
I'm comfortable with .NET in the non-web world, but new to ASP.NET. I'm
writing a very simple form where you enter your email address, click Submit,
and we add it to a text file. But I want to prepopulate the textbox with a
value from the query string so I can direct someone to
http://www.mysite.com/[email protected] for example, and the
form would already have (e-mail address removed) in the textbox. Simple enough, this
works:
private void Page_Load(object sender, System.EventArgs e)
{
textEmail.Text = Request.QueryString["email"];
}
Then when they click Submit, I want to write the contents of textEmail.Text
to a file. Also simple:
private void btnSubmit_Click(object sender, System.EventArgs e)
{
StreamWriter writer = File.AppendText(@"c:\path\addresslist.txt");
writer.WriteLine(textEmail.Text);
writer.Close();
}
But when the user clicks Submit, the page reloads, textEmail.Text is always
set back to what's in the query string, and that's the value that gets
written to the file. If they got to the page and decided to type in a
different email address, the value they type in is ignored because as soon
as they hit Submit it gets switched back to the QueryString value.
There must be a common way to fix this problem. What am I missing?
Thanks in advance for your help.
Nate Hekman
Calgary, Alberta, Canada
writing a very simple form where you enter your email address, click Submit,
and we add it to a text file. But I want to prepopulate the textbox with a
value from the query string so I can direct someone to
http://www.mysite.com/[email protected] for example, and the
form would already have (e-mail address removed) in the textbox. Simple enough, this
works:
private void Page_Load(object sender, System.EventArgs e)
{
textEmail.Text = Request.QueryString["email"];
}
Then when they click Submit, I want to write the contents of textEmail.Text
to a file. Also simple:
private void btnSubmit_Click(object sender, System.EventArgs e)
{
StreamWriter writer = File.AppendText(@"c:\path\addresslist.txt");
writer.WriteLine(textEmail.Text);
writer.Close();
}
But when the user clicks Submit, the page reloads, textEmail.Text is always
set back to what's in the query string, and that's the value that gets
written to the file. If they got to the page and decided to type in a
different email address, the value they type in is ignored because as soon
as they hit Submit it gets switched back to the QueryString value.
There must be a common way to fix this problem. What am I missing?
Thanks in advance for your help.
Nate Hekman
Calgary, Alberta, Canada