C# .NET - how to get values from one form to another form in asp.net

Asked By saran vasan
11-Feb-12 08:43 AM
when i click a save button the values which I've given to  a text box in first form that should be added in dropdownlist  which is in another form. that has to be saved in database as well..  pls anybody help to resolve this.. I"ve used  asp.net with c sharp and sql
  Ajay replied to saran vasan
11-Feb-12 09:23 AM
Hi

First of all insert the values into the database in the save button click event of first form then in second form you fetch the values from data base to data set  then bind the drop down with the data set values.

regards 
ajay
  dipa ahuja replied to saran vasan
11-Feb-12 09:49 AM
there are two ways to pass data between web forms:
 
1. QueryString
2. Session
3. PreviousPage
 
► Using QueryString
 
protected void Button1_Click(object sender, EventArgs e)
{
  Response.Redirect("Default.aspx?name=" + TextBox1.Text);
}
 
protected void Page_Load(object sender, EventArgs e)
{
  string name = Request.QueryString["name"].ToString();
}
 
► Using Session:
 
protected void Button1_Click(object sender, EventArgs e)
{
  Session["name"] = TextBox1.Text;
  Response.Redirect("Default.aspx");
}
 
protected void Page_Load(object sender, EventArgs e)
{
  string name = Session["name"].ToString();
}
 
► Using PreviousPage:

 
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

 
protected void Button1_Click(object sender, EventArgs e)
{
  Response.Redirect("Default.aspx");
}
 
On Default.aspx:
protected void Page_Load(object sender, EventArgs e)
{
  string name = ((TextBox)this.PreviousPage.FindControl("TextBox1")).Text.ToString();
  Response.Write(name);
}
 
 
  D Company replied to saran vasan
11-Feb-12 11:06 AM
Hello friend,

first of all, i'm not sure where there are any form controls in asp .net either it is page or something else like iframe  but form controls or in windows application anyway, if it is windows application than u can create the object of first form in the second page and fetch the value.


or

if it is a web application than on click of your control simple save the value in database using ado.net, i'm assuming here that u have prior knowledge of ado.net and than on the page_load method of second page u can fetch the value.


let me know in case u need more help on this!!
D
  kalpana aparnathi replied to saran vasan
11-Feb-12 12:15 PM
hi,

You can just use Session and pass the values.I am sure there might be some other way this is simple way to do.


Example


Session("textboxval") = txtbox1.value;


Call this session value on another page as


str = Session("txtboxval")


Thnanks,
  Danasegarane Arunachalam replied to saran vasan
12-Feb-12 01:06 AM
You could use the any of the ways listed here


1. Using Query Strings
2.Using Sesssion State
3. Accessing the previous page values using Page.PreviousPage Property


http://msdn.microsoft.com/en-us/library/6c3yckfw%28v=vs.80%29.aspxMSDN link explores the listed options
Create New Account
help
validator code behind protected void lnkInsert_Click(object sender, EventArgs e) { TextBox name = (TextBox)TextBox.FindControl("name").ToString(); . . . . is it correct . . ??if not . . .make it correction protected void lnkInsert_Click(object sender, EventArgs e) { TextBox name = (TextBox)Page.FindControl("name"); or you can directly also access the text box like string strName = name
Hi I want to get server side control in static web methods in c# using page.findcontrol("textbox") Page page = (Page)HttpContext.Current.Handler; Panel ltr = (Panel)page.FindControl("panelID"); but it return null in ltr object. . . . how can i access server side public static string Result( string controlName) { return RenderControl(controlName); } public static string RenderControl( string controlName) { Page page = new Page (); UserControl userControl = ( UserControl )page.LoadControl(controlName); userControl.EnableViewState = false ; HtmlForm form = new HtmlForm
findcontrol in my page p1 = planetlist.SelectedValue.ToString(); foreach (Control page_control in Page.Controls) { foreach (Control c in page_control .Controls) { if (c is TextBox) { if (c = = (TextBox)Page.FindControl("txt1")) { ((TextBox)c).Text = p1.ToString(); } else if (c = = (TextBox)Page.FindControl("TextBox1")) { ((TextBox)c).Text = p1.ToString(); } else if (c = = (TextBox)Page.FindControl("TextBox2")) { ((TextBox
regarding ((TextBox)LoginView1.FindControl("UserName")).Text Can I do string A = (( TextBox )LoginView1.FindControl( "UserName" )).Text ? So, it depends on where you call this line of code. TextBox textBox = (TextBox)LoginView1.FindControl( "UserName" ); if (textBox ! = null ) { string A = textBox.Text; } string A = ""; system.web.UI.webcontrol myControl = loginview1.findcontrol("username"); if ( (myControl ! = null) && (myControl GetType() = = TypeOf(TextBox)) ) a = mycontrol.text; I am still getting same error: Message: Exception of type 'System.Web
i m adding rows dynamically on add button click using javascript like: name age salary textbox textbox textbox(on add button click) textbox textbox textbox(on add button click) textbox textbox textbox(on add button click) there is also a delete button for each row to