Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    95
    Thanks
    14
    Thanked 0 Times in 0 Posts

    ASP.NET calls the first declared asp-controlīs onclick when javascript is disabled

    Hi!
    When I press enter in the asp-textbox, the first declared asp-controlīs onclick is fired when javascript is disabled. Why is that?

    I have two imagebuttons (ids: "changelang" and "search") which both have a onclick-event. The imagebutton with the id "changelang" is appearing first on the website and itīs onclick-event is therefore fired when pressing enter in the textbox (id: tb) when javascript is disabled. How do I change, so a specific id is fired?

    Code:
    function SearchClick(obj)
    {
        if (window.event.keyCode == 13)
        {
            document.getElementById(obj).click();
            return false;
        }
        else
            return true;
    }
    codebehind:

    Code:
    tb.Attributes.Add("onkeypress", "return SearchClick('" + search.ClientID + "');");
    Last edited by earni23; 09-14-2010 at 08:57 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2009
    Posts
    244
    Thanks
    1
    Thanked 20 Times in 20 Posts
    Hey earni23,

    Two things:

    #1. The OnClick event is server-side. There is however an OnClientClick event available on some of the server-side controls (past framework 2.0, I think). Sure you're not mixing those up?

    #2. Regarding your two imagebutton controls, this has to do with setting the focus on whatever control you want. You can do this either via server or client-side. I suppose you will want to do it via server-side, so just put the following inside your Page_Load method:
    Code:
    	changelang.Focus();
    Regards,
    Mike


  •  

    Posting Permissions

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