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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Posting With a Button Click

Status
Not open for further replies.

justTryingToCode

Programmer
Nov 14, 2006
13
US
Hi all experts.

I am new to c# .NET and have a question about submitting a form on a button click event.

I want to post form data to a new page after validating data with a custom validator control. I have everything working except the post part. Here is my code:

protected void btnGo_Click(object sender, EventArgs e)
{
valDateValidator.Enabled = true;
Page.Validate();
if (Page.IsValid)
{
???? Post form data to new page...
}

}

Thank you in advance..
Jon
 
Hi Jon,

You might have more luck/more responses if you trie posting in the asp.net forum:


You can do two things to send the data to another page:

1 form a url containing the new page and the data as request variables and use response.redirect to go to the new page, where the request varaibles will be read out, as in:

response.redirect(
2 put the data in session variables, redirect to the new page and read the data from the session.

Each method has its pros and cons.
 
Following Painkillers suggestions, here's what I would do:

protected void btnGo_Click(object sender, EventArgs e)
{
valDateValidator.Enabled = true;
Page.Validate();
if (Page.IsValid)
{
//add data to session variable
string stringVariable = "My Variable";
Session.Add("variablename", stringVariable);
}

}
That's the variable stored in a session, which can be read back by elsewhere in your form, i.e.

protected void Page_Load(object sender, EventArgs e)
{
string stringVariable = (String)Session["variablename"];
}

Simple as that.
 
Thank you markknowsley.

That is a solution I had in mind, but Im concerned about people having session vars not on.

You would think this would be simple.. LOL a form post..

thanks for all your help, I will keep looking and post a solution when I find it, unless someone gets to it first.

Jon
 
I am going to use javascript injection to do the post.

If anyone has a better way, please post it up here for reference. I will check back later.

Thank you to everyone who took some time to read answer my issue.

Jon
 
Well Javascript injection gave some MAC errors, but the good news is I found out what to use by googling that error.

Apparently using Server.Transfer("<new_page_name>",true)

Does the post and preserves the form data.

Thanks again for all your help.
Jon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top