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

Passing a web form as an object to another FORM?

Status
Not open for further replies.

nomi2000

ISP
Feb 15, 2001
676
CA
Hi guys
I have a form say call WEBFORM1.aspx it has different texboxes and other controls in it,on a press of a button say (VALIDATE) i want to open another web-form say WEBFORM2.aspx which could see all the control in WEBFORM1 ?
Is it possible using ASP .Net?
I have done fairly easy in VB .Net but not sure how to do in ASP
Regards
Nouman

Nouman Zaheer
Software Engineer
MSR
 
Well, you could create a Web User Control, that consisted of just the actual text boxes and other input controls layed out how you would like them.

Use it on each page. This is useful for re-using a form for a couple of things, such as an "Account Editor" which is used to create new accounts as well as for users to edit their existing information. You want this done on separate pages, but not have to create the whole form over again.

Not use how it applies to Validation though - maybe there is another way to do what you want.

Greetings,
Dragonwell
 
Yes, you can do this. You would pass the instance variable of the first form to the second form. Remember, in .NET, forms are objects.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
You can use Server.Transfer("WEBFORM2.aspx", true). This way you'll be transfered to page2 while having all controls and their values from page1 available through Request.Form:
Code:
//in WEBFORM1.aspx:
<asp:TextBox Runat=server ID="myText" />
<br>
<asp:DropDownList ID="myList" Runat=server>
  <asp:ListItem Value="one">One</asp:ListItem>
  <asp:ListItem Value="2">Two</asp:ListItem>
  <asp:ListItem Value="3">Three</asp:ListItem>
</asp:DropDownList>
<br>
<asp:Button ID="btnValidate" Runat=server Text="Do Transfer" />
..........................
private void btnValidate_Click(object sender, System.EventArgs e)
{
  Server.Transfer("WEBFORM2.aspx", true);
}

//in WEBFORM2.aspx
// write out values from controls on WEBFORM1.aspx:
Response.Write("Text Box: " + Request.Form["myText"] + "<br>");
Response.Write("Drop Down: " + Request.Form["myList"]);
There is a known bug when using Server.Transfer, here is a link to an MSDN article:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top