Re-Using form input value in code behind


I am trying to reuse an input value from a form in multiple areas in my code behind. My aspx file uses panels. first panel sets the value of a name and posts it to a dB: eg

<asp:TextBox ID="name" runat="server" width="180" MaxLength="50" />

<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click"/>

code behind:

protected void Button1_Click(object sender, EventArgs e)


SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDB"].ConnectionString);


string sql = "insert into supplier (name) Values (" + name.Text + "')";

SqlCommand command = new SqlCommand(sql, connection);




P1.Visible = false;

P2.Visible = true;


I want to use the value from name.Text in another OnClick event, for simplicity sake I just want to write it.

protected void Button2_Click(object sender, EventArgs e)


Response.Write("here is the variable" + name.Text);


It won't write and therefore I can't use it in other events





3/10/2006 5:38:29 PM 93655 articles. 5 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 58

That will work as long as there is a Button2 and a Button2_Click event handler in the same page class.


3/10/2006 6:22:59 PM


Thanks for taking a look.....

You know, some times it pays to take a break and walk away. It does work, I was not putting data into the form field so it obviously would not display..........

Thanks again,




3/10/2006 7:14:22 PM

No problem Doug. Happens to all of us at one time or another.



3/11/2006 7:39:32 PM

Similar Artilces:

Web Forms Designer error
Hi, The web forms designer keeps adding things in a generated InitializeComponent() method. I believe these things shouldn't be there because I've made a new webform with the same code that doesn't add the same stuff. Is there anyway I can see the Web Designer code? Thanks. Just expand out the hidden #region. It is labeled Web Form Designer CodeStarting with ASP.NET 2.0? Look at:Programming Microsoft Web Forms My Blog...

can someone one give me difference between web form and mobile web form and which or where or when i'm using the forms?
thanks Marc Hi Marc, Based on my understanding, you want to know the differences between the ASP.NET web application and ASP.NET mobile web application. If I have misunderstood you, please feel free to let me know. The ASP.NET forms are used to develop the ASP.NET pages for desktop browsers and The ASP.NET mobile forms are used to develop the ASP.NET pages for mobile device browsers. When we create the ASP.NET mobile web forms pages, we can use nearly all the features of ASP.NET. But there are a couple of compatibility issues: Error Handling and Reporting. Tracing. Using Redi...

Use datastore in Web form code-behind
I am developing a new web application. I have some reports in old legacy system that are written in PB but have to migrate to web. So I migrate the old dw by Datawindow Designer first. And I decide to instance a datastore in web form code-behind, set its datawindow object and retrieve, then save the output as pdf or excel and redirect the saved file back to the browser. The following is the piece of C# codes: Sybase.DataWindow.DataStore ds = new Sybase.DataWindow.DataStore(); this.oleDbConnection1.Open(); Sybase.DataWindow.AdoTransaction tran = new Sybase.DataWindow.AdoTransa...

how to change these windows form code to web form code?
hi, i'm a beginner of c#,i want to know how to change these windows form code to web form code //////////// private void buttonSign_Click( object sender, System.EventArgs e) { //get original message as byte array byte[] messagebytes = Encoding.UTF8.GetBytes( textOriginalMessage.Text); //create digest of original message using SHA1 SHA1 sha1 = new SHA1CryptoServiceProvider(); byte[] hashbytes = sha1.ComputeHash(messagebytes); //display hash bytes in hex format StringBuilder sb = new StringBuilder(); for (...

Passing Values from a Web Form to Another Web Form
Hello All! I am trying to pass values from one web form to another web form. I know that there are 3 ways of doing this: queryString, Server.Transfer and Session. I am using the Server.Transfer method. But I am not able to create, in my 2nd web form, an instance of my 1st web form. My 1st Web form is named CallTrack.aspx and my 2nd is named Export.aspx. What I mean is something like this: Public value as CallTrack. I can't create it in my 2nd web form because when the intellisense is displayed, there's no CallTrack in the options. Thanks!   How about using cross-...

referencing textboxes on web forms using code behind
 Hello: On my web form I have several text boxes named from textbox1 to textbox30. How do I "reference" these text boxes in code behind ""? Say i wish to write a for loop. for i = 1 to 30 textbox[i].text.length>0 stmt... next i How do I code this part? You can get idea from following link to click “Mark as Answer” on the post If you get answer from this post(s) ! Try the FindControl method.For i = 1 To 30 Dim txt As...

Getting the values form the previous form and re-use in saving connection doesn't work...
Hello,I have a web form and each web form is saving to a specific user folder.  When the user login with their username and password and go to the web form, fill-out all the information and save to the user folder database, the saving data to the database is working, but now I want to change the directory of the saving data to a specific user folder control db that based on the username, but seems like didn't get to the right user valid path, So instead of this directory 'C:\WINNT\profiles\controls\test.mdb' , I want to save it in a user folder database with their username l...

Implementing .Net Form into an web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Getting undefined value while using view state in Web Form Designer generated code
hi,    i am trying to get the drop down list selected value in Web Form Designer generated code,when i am trying it with view state i am getting some undefined value.please help me regarding this.. i am trying with the following code.        refinery =  ddRefineries.SelectedRefinery; ViewState.Add("ref1",refinery); #region Web Form Designer generated code        override protected void OnInit(EventArgs e)        {          &nbs...

Need Windows Form to Retrieve Information From Web Form
I have a cash and carry web site that customers can order products, the next day come in to the company to pay and pickup. I would like to create a windows application for the company to do two things: 1. download all the orders from the day before 2. upload price changes, product changes, category changes I've search the internet and forums and the only thing I can find that I think would actually link these two together would be a web service. Can you please tell me if I am heading in the right direction or if there is another method to link the two applications, if there are any pitf...

windows forms in vb .net into web forms
we are creating a database driven website as part of our project. currently we have forms connecting to the database created in visual basic. these windows forms we need to convert into web forms which are asp .net compatible. can u give me an answer or show me a way. Hi, because of the difference in nature between web and win applications you'll need to reimplement at least the UI part. If you have a multitiered application in which the busines logic and data access are in different parts/assemblies you can reuse them. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Wor...

Using Win Form controls in web forms
Hi All,   Please tell me if i can't use the window forms controls in my webform. What if i simply import the Namespace. Definitely this will help me to expose the class & methods, but will they work accordingly when get rendered. I am totally confused.. please help me. Thanks Simple answer:  You can't.  Webforms controls render as HTML; while this may be possible to achieve with Winforms controls by invoking the design-time rendering, I doubt it's going to work very well.What control are you trying to use?Peter BrunoneMS MVP, ASP.NETFounder, Easy...

getting values from a web form to windows form
Hot Requirement ..... Is there any possible of getting values from a web form to windows form ????? Yes One way i to use the WebRequest and WebResponse classes of the System.Net namespace. For example:  WebRequest request = WebRequest.Create("URL of the web page); WebResponse response = request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string content = reader.ReadLine(); ....    Reza Nassabehwww.professionalcsharp.comDon't forget to click "Mark as Answer" on the post that helped you. That way fut...

Web forms and mobile web forms
Hey everyone, I am looking to develope a web site that depending on the device connecting to it, it will display a certain page. In this case im looking to create a web and wap version of the same project. I have the Web forms version finished using ASP.NET and C# and I am wondering how to create the mobile web form and incorporate it in the project. In the project folder, can I just add a mobile web??? But what about displaying device specific pages?? Cheers -Dudach Yes, you can add mobile web forms and controls to your Web Application project. No problem. For device/br...

Web resources about - Re-Using form input value in code behind -

Re-Using The LCD & Button Assembly From A Broken Inkjet Printer
Inkjet printers are a dime a dozen. You probably have taken old printers apart to scavenge parts like motors, pulleys, belts, switches, linear ...

Resources last updated: 12/13/2015 10:08:11 PM