What is the best way to have a page read values posted from another page? I have something that works, but it seems rather sloppy.
I'm working on a multi-page form with the first page using PostBackUrl to go to the second.
Within page 1 is content placeholder named "CPH1". Inside that is a field named "First_Name".
I submit the first page to the second using PostBackUrl.
The code behind file of the second page then reads the value and places it into a variable using this code:
protected void Page_Load(object sender, EventArgs e)
{
NameValueCollection nvc = Request.Form;
string First_Name_Here = nvc["ctl00$CPH1$First_Name"] ;
}
As you can see, I'm getting the info by using the final name of the field, "ctl00$CPH1$First_Name", instead of "First_Name".
Is there a better way of doing this?
Edit below:
Thanks to everyone for their help. Still haven't figured this out, but have gotten closer.
Using this code: ContentPlaceHolder CPH1 = Page.Master.FindControl("CPH1") as ContentPlaceHolder; Response.Write(CPH1.FindControl("First_Name"));
Gives me this result: System.Web.UI.WebControls.TextBox.
What I haven't figured out is how to get the value of the TextBox as a string. It seems like anything I try results in an error.