Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1031575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:57:03+00:00 2026-05-16T13:57:03+00:00

Possible Duplicate: Link Button on the page and set it as default button, work

  • 0

Possible Duplicate:
Link Button on the page and set it as default button, work fine in IE but not in Mozila

How to set linkbutton as default button for asp:panel in asp.net? I know a button can be set as default but my application uses linkbuttons for all forms. Any suggestion how it can be done.

EDIT:

Now i tried this,
It works in firefox as well but my javascript validation (ie) onclient click of my linkbutton doesn’t work why?

var __defaultFired = false;

        function WebForm_FireDefaultButton(event, target) {
            var element = event.target || event.srcElement;

            if (!__defaultFired && event.keyCode == 13 && !(element && (element.tagName.toLowerCase() == "textarea"))) {
                var defaultButton;

                if (__nonMSDOMBrowser)
                    defaultButton = document.getElementById(target);
                else
                    defaultButton = document.all[target];

                if (defaultButton) {
                    if (typeof (defaultButton.click) != "undefined")
                        defaultButton.click();
                    else
                        eval(unescape(defaultButton.href.replace("javascript:", "")));

                    event.cancelBubble = true;

                    if (event.stopPropagation) event.stopPropagation();
                    return false;
                }
            }
            return true;
        }

Second EDIT:

I was able make my custom linkbutton control work but couldn’t able to hook OnClientClick to it. Source using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net.

and i did this,

<%@ Register Namespace="App_Code" TagPrefix="ac" %>
<asp:Label runat="server" ID="lblHello" />
<asp:Panel runat="server" DefaultButton="lbHello">
    First name: <asp:TextBox runat="server" ID="txtFirstName" />
    <ac:LinkButtonDefault ID="lbHello" runat="server" Text="Click me" 
        OnClientClick="javascript:alert('hai');" OnClick="lbHello_Click" />
</asp:Panel>

My Clientside function doesn’t work why? Any suggestion.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T13:57:04+00:00Added an answer on May 16, 2026 at 1:57 pm

    Rather than use a custom control you could take the simple approach of adding an attribute to handle the textbox’s onKeyPress event. This correctly handles pressing Enter from the textbox and triggering the LinkButton‘s event. The downside to this approach is that any LinkButton OnClientClick event will not be triggered in Firefox, which is related to the issue described in that blog post you linked to. It will only be triggered when the user actually clicks on the link with their mouse. However, in IE, it will trigger from both the textbox and from being clicked on directly.

    Solution #1 – The code to add the attribute is as follows:

    protected void Page_Load(object sender, EventArgs e)
    {
        txtFirstName.Attributes.Add("onKeyPress",
            "javascript:if (event.keyCode == 13) __doPostBack('" + lbHello.ClientID + "','')");
    }
    

    Try that and see if it fits your needs. Just bear in mind the limitation I described earlier.

    Now, if you want the above limitation to go away, one of the comments from that blog post showed an approach that appears to work correctly. I’ve modified it to get rid of the StringBuilder and converted it to C#.

    Solution #2 – The code to add the function and register it is as follows:

    protected void Page_PreRender(object sender, EventArgs e)
    {
        string addClickFunctionScript = @"function addClickFunction(id) {
               var b = document.getElementById(id);
               if (b && typeof(b.click) == 'undefined')
                 b.click = function() {
                   var result = true;
                   if (b.onclick) result = b.onclick();
                   if (typeof(result) == 'undefined' || result)
                     eval(b.getAttribute('href'));
                 }
             };";
    
        string clickScript = String.Format("addClickFunction('{0}');", lbHello.ClientID);
    
        Page.ClientScript.RegisterStartupScript(this.GetType(), "addClickFunctionScript", addClickFunctionScript, true);
        Page.ClientScript.RegisterStartupScript(this.GetType(), "click_" + lbHello.ClientID, clickScript, true);
    }
    

    Page Markup –
    The page mark-up is the same for both of the aforementioned solutions:

    <asp:Label runat="server" ID="lblHello" />
    <asp:Panel ID="Panel1" runat="server" DefaultButton="lbHello">
        First name:
        <asp:TextBox runat="server" ID="txtFirstName" />
        <asp:LinkButton ID="lbHello" runat="server" Text="Click me" OnClick="lbHello_Click"                 
             OnClientClick="javascript:alert('Hello, World!');"/>
    </asp:Panel>
    

    In both cases a custom control is not needed to achieve this type of functionality. Keep it simple.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: open download dialog with php I have a link in my page
Possible Duplicate: Making a <button> that's a link in HTML How apply CSS to
Possible Duplicate: Single Linked List is Palindrome or not Suppose i have a link
Possible Duplicate: Javascript force open a link in a browser I am working on
Possible duplicate of: should-i-link-to-google-apis-cloud-for-js-libraries also many other discussions, including: Where do you include the
Possible duplicate: How can i give app store link in my apps before approving
Possible Duplicate: include after PHP 404 header returning “Oops! This link appears to be
Possible Duplicate: Playing .mp3 and .wav in Java? Friends, please tell me link if
Possible Duplicate: Hyperlinks showing URL with Blueprint If i include blueprint all my link
Possible Duplicate: How do I call unmanaged C/C++ code from a C# ASP.NET webpage

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.