Submit a WebForm
-
Suppose I have two webforms WebForm1 and WebForm2 and now I want to Submit Webform1 to WebForm2 and get the values of form fields of WebForm1 fron WebForm2 using Request.Form method. Please help.:laugh: I am a Software Developer using C# on ASP.NET.
-
Suppose I have two webforms WebForm1 and WebForm2 and now I want to Submit Webform1 to WebForm2 and get the values of form fields of WebForm1 fron WebForm2 using Request.Form method. Please help.:laugh: I am a Software Developer using C# on ASP.NET.
There are different ways to accomplish this. One is here with querystrings. put this code to your submit button event handler.
private void btnSubmit_Click(object sender, System.EventArgs e) { Response.Redirect("Webform2.aspx?Name=" + this.txtName.Text + "&LastName=" + this.txtLastName.Text); }
Put this code to second page page_loadprivate void Page_Load(object sender, System.EventArgs e) { this.txtBox1.Text = Request.QueryString["Name"]; this.txtBox2.Text = Request.QueryString["LastName"]; }
This way you can get values. Querystring is shown in address bar of your browser therefore you should not use this way to send sensitive information. & is used to distinguish between variables. You can also reach QueryString variables using indexers.foreach( string s in Request.QueryString) { Response.Write(Request.QueryString[s]); Response.Write("///"); }
ORfor (int i =0;i < Request.QueryString.Count;i++) { Response.Write(Request.QueryString[i]); Response.Write("///"); }
I remember reading in somewhere that browsers have some capacity for QueryString length. If you need to send a variable which contains & such as "Mark & Spencer", you have a problem. I have read Server.UrlEncode solves this problem. But below is my solution.private void btnSubmit_Click(object sender, System.EventArgs e) { string p1 = this.txtName.Text.Replace("&","%26"); string p2 = this.txtLastName.Text.Replace("&","%26"); string sln = "WebForm2.aspx?" + "Name=" + p1 + "&LastName=" + p2; Response.Redirect(sln); }
Same solution is in Microsoft .Net Quick Start tutorials. ASP.NET--- Working with Web Controls --- Performing Page Navigation (Scenario 1) Performing Page Navigation (Scenario 2) See them also if you want to see more example for this technique. Second solution would be usage of SessionState. Education is no substitute for intelligence. That elusive quality is defined only in part by puzzle-solving ability. It is in the creation of new puzzles reflecting what your senses report that you round out the definition.
Frank Herbert Education is no substitute for intelligence. That elusive quality is defined only in part by puzzle-solving ability. It is in the creation of new puzzles reflecting what your senses report that you round out the definition. Frank Herbert