Results 1 to 2 of 2

Thread: Capture values of textboxes after hitting a button

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2004
    Location
    fda
    Posts
    17

    Capture values of textboxes after hitting a button

    I would love to know if there is a way around this situation

    I have two texboxes create programmaticly. I want to capture these values and update it somewhere else in my form. Eventhough I have included this to my code

    TextBox tb1 = new TextBox()
    frombox.TextChanged += new System.EventHandler(this.Textbox_TextChanged);

    and the submit button is also added this code
    submitbt.Click += new System.EventHandler(Submit_Clicked);

    I don't know why it does not trigger any of these.

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    PHP Code:
    <script language="c#" runat="server">
    protected 
    override void OnInit(System.EventArgs e)
    {
        
    //You must create the controls here every time! otherwise
        //the page will "forget" them.  If they are created in the same
        //order every time they will also maintain their viewstate on postback.
        
    TextBox txtFirstName = new TextBox();
        
    txtFirstName.ID "txtFirstName";
        
    txtFirstName.AutoPostBack true;
        
    txtFirstName.TextChanged += new System.EventHandler(txtFirstName_TextChanged);
        
    FormMain.Controls.Add(txtFirstName);
        
    Button btnSubmit = new Button();
        
    btnSubmit.Text "Submit!";
        
    btnSubmit.ID "btnSubmit";
        
    btnSubmit.Click += new System.EventHandler(btnSubmit_Clicked);
        
    FormMain.Controls.Add(btnSubmit);
    }
    protected 
    void txtFirstName_TextChanged(object senderSystem.EventArgs e)
    {
        
    //This only fires when the text has been altered and focus leaves
        //the text box(i.e. you need to tab out of the text box for this event to fire)
        
    Response.Write("Text Changed!");
    }
    protected 
    void btnSubmit_Clicked(object senderSystem.EventArgs e)
    {
        
    Response.Write("Submit Clicked!");
    }
    </
    script>
    <
    html>
        <
    body>
            <
    form runat="server" id="FormMain">
                
            </
    form>
        </
    body>
    </
    html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width