CJ

The circle of life – ** .Net – Training – MOSS **

  • Past Post

  • Vistor Locations

Set default button for Enter key (ASP.Net 1.1)

Posted by Clayton James on October 23, 2007

I was looking at solutions for an ASP.Net 1.1 application to set a default button for a control when the Enter key is pressed. I came accross Jeff’s solution which I thought was simple and provided the requirements I needed.

All I needed to do was add the one line below ๐Ÿ™‚ This solution also allows you to wire up different default buttons to different form controls.

txtPropertyNo.Attributes.Add(“onKeyPress”, “javascript:if (event.keyCode == 13) __doPostBack(‘” + btnDisplayGraph.UniqueID + “‘,”)”);

You could also use the DefaultButton panel property.

Advertisements

12 Responses to “Set default button for Enter key (ASP.Net 1.1)”

  1. Anil Chauhan said

    Not a gud Idea.

  2. Elham said

    HEllo,
    Why not a good idea?
    plz Explain!!!

  3. Barry said

    I have been trying to make this work for a couple of hours and cannot get it working – Am I missing something (Using BN Net Framework 1.1)

    Using two buttons and trying to get textbox1 to initiate a button2 response. Keeps going to button1 response. See Code Below:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    TextBox1.Attributes.Add(“onKeyPress”, “javascript:if (event.keyCode == 13) __doPostBack(‘” + Button2.UniqueID + “‘,”)”)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Label1.Text = “button 1 clicked”
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Label1.Text = “Button 2 clicked”
    End Sub

    Thanks Barry

  4. Greg said

    It seems that there was a syntax error in your code and it wouldn’t work in IE (only in FireFox). I’ve tweaked it a bit and now it seems to work correctly on both browsers.

    txtLogin.Attributes.Add(“onKeyPress”, “javascript:if (event.keyCode == 13) {__doPostBack
    (‘” + btnLogin.UniqueID + “‘);return false;}”);

  5. Jose said

    Works perfect
    thanks!

  6. Caroline said

    Thanks for the code.
    My Page Load twice, so i add the “return false;” sugested.
    Now it works perfectly.

  7. Rajesh said

    Good ………..idea…..

  8. jitendra singh said

    but can somebody please tell me that what should i type in for onKeyPress, without writing this how will it call that jquery pluging, plz.

  9. jitendra singh said

    but can somebody please tell me that what should i type in asp textbox control for onKeyPress, without writing this how will it call that jquery pluging, plz.

  10. Vimal Patel said

    Dude. No need to do use javascript.

    just use below:

    or

    It works.. ๐Ÿ™‚

    • Vimal Patel said

      hi

      just use any one of below :

      asp:Panel runat=”server” DefaultButton=”btn_id”></asp:Panel
      or
      form id="form1" DefaultButton="btn_id" runat="server"

      It works ๐Ÿ™‚

  11. bprussell said

    The DefaultButton attribute doesn’t exist in ASP.NET 1.1 which is what this topic is about.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: