Problem with default button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Morten

    Problem with default button

    Hi!

    I have a problem that's driving me nuts:

    I have a webform with a user control containing a number of buttons at the
    top. On my form I have a search button that I want to be the default
    button - so that if you type something into one of the fields on my form and
    hit <Return> this button is activated. I have made sure that the
    "TextChange d" method of the input field of my form should trigger a search
    button click.

    The problem is that if I hit the <Return> key I always trigger the first
    button of my user control - an ImageButton control.

    Does anyone have a suggestion that will help me change this behaviour?

    Thanks in advance.

    Morten


  • Cor Ligthert

    #2
    Re: Problem with default button

    Hi Morton,

    Can you try this and tell if it works with a button too?
    (It works with a textbox).

    I did not try it with the button until now

    Cor

    It need to added in the HTML, the most things are possible with register
    script however as far as I know this one not.

    //This should be the last rows in your html aspx file
    <script language="JavaS cript">
    Button1.focus() ;
    </script>
    </HTML>


    Comment

    • Morten

      #3
      Re: Problem with default button

      Hi!

      Thanks for your reply. Unfortunately I couldn't make your suggestion work.

      Best regards

      Morten

      "Cor Ligthert" <notfirstname@p lanet.nl> wrote in message
      news:O1hqKAQLEH A.1032@tk2msftn gp13.phx.gbl...[color=blue]
      > Hi Morton,
      >
      > Can you try this and tell if it works with a button too?
      > (It works with a textbox).
      >
      > I did not try it with the button until now
      >
      > Cor
      >
      > It need to added in the HTML, the most things are possible with register
      > script however as far as I know this one not.
      >
      > //This should be the last rows in your html aspx file
      > <script language="JavaS cript">
      > Button1.focus() ;
      > </script>
      > </HTML>
      >
      >[/color]


      Comment

      • Cor Ligthert

        #4
        Re: Problem with default button

        Hi Morton,

        I thought you did want to set a button as default.
        Which not even is possible I see now.

        However you can archieve more simple your sollution when you set your
        textboxes all with the option *autopostback* and create one sub, with as
        eventhandlers textboxX.textCh anged for all textboxes you want to use for
        that.

        If something is unclear, feel free to ask that.

        Cor


        Comment

        • Morten

          #5
          Re: Problem with default button

          Hi again!

          I can't quite seem to make it work. I have a text field called
          TicketSearchFie ld , some check boxes and a drop-down. The button I'm hoping
          to activate by means of hitting the <Return> key is called SearchSupport.
          I've set the properties of TicketSearchFie ld to "AutoPostBa ck = True". I've
          also added an event handler for the text field that looks like this:
          Private Sub TicketSearchFie ld_TextChanged( ByVal sender As Object, ByVal e As
          System.EventArg s) Handles TicketSearchFie ld.TextChanged

          SearchSupport_C lick(sender, e)

          End Sub

          I would have thought that this was all I need to do but for some reason the
          wrong button is activated:-(

          Best regards

          Morten

          "Cor Ligthert" <notfirstname@p lanet.nl> wrote in message
          news:uCImpYRLEH A.3944@tk2msftn gp13.phx.gbl...[color=blue]
          > Hi Morton,
          >
          > I thought you did want to set a button as default.
          > Which not even is possible I see now.
          >
          > However you can archieve more simple your sollution when you set your
          > textboxes all with the option *autopostback* and create one sub, with as
          > eventhandlers textboxX.textCh anged for all textboxes you want to use for
          > that.
          >
          > If something is unclear, feel free to ask that.
          >
          > Cor
          >
          >[/color]


          Comment

          • Cor Ligthert

            #6
            Re: Problem with default button

            Hi Morten,

            My problem is to understand you, why do you need a button?
            The Enter itself acts already as a button.

            When you want, you can add the handler to the same event as the handler from
            the button.

            When you are not using the "sender" and the eventargument, than you can do
            in the checkbox change event something as

            textboxvalue changed event
            mysub(nothing,n othing)
            (there are better ways, however to show you a simple method.

            What do I miss?

            Cor


            Comment

            • Morten

              #7
              Re: Problem with default button

              Hi again!

              I have a user control at the top of my form containing 5 buttons that people
              use for various purposes. It's one of these buttons that always gets
              activated when I click <Enter>. I don't think it'll change anything if I
              remove my search button. As you can see from the code I posted yesterday I
              already have an event handler for the textbox control and it's supposed to
              emulate a click of the search button.

              I probably don't understand what you're trying to say. Can you perhaps
              provide a code sample?

              Best regards

              Morten

              "Cor Ligthert" <notfirstname@p lanet.nl> wrote in message
              news:OY62oJcLEH A.3892@TK2MSFTN GP11.phx.gbl...[color=blue]
              > Hi Morten,
              >
              > My problem is to understand you, why do you need a button?
              > The Enter itself acts already as a button.
              >
              > When you want, you can add the handler to the same event as the handler[/color]
              from[color=blue]
              > the button.
              >
              > When you are not using the "sender" and the eventargument, than you can do
              > in the checkbox change event something as
              >
              > textboxvalue changed event
              > mysub(nothing,n othing)
              > (there are better ways, however to show you a simple method.
              >
              > What do I miss?
              >
              > Cor
              >
              >[/color]


              Comment

              • Cor Ligthert

                #8
                Re: Problem with default button

                Hi Morten,

                This should go.
                'All webform controls,
                'One Button (or more if you wish)
                'A label and a Textbox on the page
                \\\
                Private Sub Page_Load(ByVal sender As System.Object, _
                ByVal e As System.EventArg s) Handles MyBase.Load
                Me.TextBox1.Aut oPostBack = True 'this always
                End Sub
                Private Sub Button1_Click(B yVal sender As System.Object, _
                ByVal e As System.EventArg s) Handles Button1.Click
                Search()
                End Sub
                Private Sub TextBox1_TextCh anged(ByVal sender As _
                System.Object, ByVal e As System.EventArg s) _
                Handles TextBox1.TextCh anged
                Search()
                End Sub
                Private Sub Search()
                Me.Label1.Text = Me.TextBox1.Tex t
                End Sub
                ///
                I hope this helps?

                Cor

                And this in the end of your HTML than it looks real nice

                </form>
                <script language="JavaS cript">
                document.all("T extBox1").focus ();
                </script>
                </body>
                </HTML>


                Comment

                Working...