Get text in TextBox without pressing Enter key

Discussion in 'ASP .Net' started by mg, Jul 14, 2003.

  1. mg

    mg Guest

    I want to enter characters in a TextBox in a WebForm,
    press a Button in the WebForm, and read the characters
    that were typed into the TextBox from within the
    Button_Click event handler. The main point here is that I
    want to read the value typed into the TextBox without
    hitting the Enter key or setting focus on another
    control ...
     
    mg, Jul 14, 2003
    #1
    1. Advertisements

  2. mg

    mg Guest

    P.S. I need a C# solution. Thanks.
     
    mg, Jul 14, 2003
    #2
    1. Advertisements

  3. mg

    dj Bass Guest

    double clicking on the button in the design view that you want to use will
    provide you with the event handler you require, alternatively you can just
    create a empty method which would look something like this:

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles btnSubmit.Click

    end sub.


    then, say your edit box has the id = "editBoxText". You'll be able to call
    the editBoxText.Text() method on that member variable created for that
    control and access the text.

    is that what you wanted or did i miss the boat?

    if you want to set the focus from the submit button back to the edit box,
    check out this website for a short method on setting focus...

    http://aspnetweblog.com/posts/7115.aspx
     
    dj Bass, Jul 14, 2003
    #3
  4. mg,

    Then the code that dj Bass just gave you is what you want.

    You get the text with:

    MyTextBox.Text

    Justin


     
    S. Justin Gengo, Jul 14, 2003
    #4
  5. mg

    dj Bass Guest

    Unless you expect the event handler for a button to simply pick up the text
    from the text box as you write? which wouldn't work, you'd need an event
    handler for the text box on the text change event...

    as they say in Zulu, angaas.

     
    dj Bass, Jul 14, 2003
    #5
  6. mg

    Vikram.NET Guest

    Hi,

    It is not clear what you actually want to do.

    You have said that after entering text in the textbox, you
    will be pressing a Button in the web form. When you press
    the button obviously, the textbox control will lose focus
    and the Button will get focus.

    As far as getting the text of the textbox is concerned, it
    can be done very easily by writing the event handler for
    Button's Click event as follows:

    private void Button1_Click(object sender,
    System.EventArgs e)
    {
    string Value;
    Value = TextBox1.Text;
    }

    Value will contain the text entered in the textbox.

    Regards,
    Vikram
     
    Vikram.NET, Jul 14, 2003
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.