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 8683951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:10:20+00:00 2026-06-12T22:10:20+00:00

I have a custom web control *.ascx file. I am trying to simulate the

  • 0

I have a custom web control *.ascx file. I am trying to simulate the user clicking the update button in a gridview using a java script. I have this script at the top of my .ascx page :

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript">

        $(document).keypress(function (e) {
            if (e.which == 13) {
                document.getElementById("LinkButton1").click();
            }
        });

    </script>

The “LinkButton1” is located in this template field:

  <asp:TemplateField ShowHeader="False">
                      <EditItemTemplate>
                          <asp:LinkButton ID="LinkButton1" runat="server" onKeyPress="" UseSubmitBehavior="True" CausesValidation="True" 
                              CommandName="Update" TabIndex="13" Text="Update"  ></asp:LinkButton>
                          &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                              CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                      </EditItemTemplate>
                      <ItemTemplate>

What am I missing or doing wrong?

  • 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-06-12T22:10:22+00:00Added an answer on June 12, 2026 at 10:10 pm

    That won’t work because the click only works for attached events not for an anchor which is what a linkbutton is rendered as.

    You can use this ..

    $(document).keypress(function (e) {
            if (e.which == 13) {
        simulate(document.getElementById("LinkButton1"), "click");
    
            }
        });
    

    function simulate(element, eventName) {
    var options = extend(defaultOptions, arguments[2] || {});
    var oEvent, eventType = null;

    for (var name in eventMatchers) {
        if (eventMatchers[name].test(eventName)) { eventType = name; break; }
    }
    
    if (!eventType)
        throw new SyntaxError('Only HTMLEvents and MouseEvents interfaces are supported');
    
    if (document.createEvent) {
        oEvent = document.createEvent(eventType);
        if (eventType == 'HTMLEvents') {
            oEvent.initEvent(eventName, options.bubbles, options.cancelable);
        }
        else {
            oEvent.initMouseEvent(eventName, options.bubbles, options.cancelable, document.defaultView,
              options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
              options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element);
        }
        element.dispatchEvent(oEvent);
    }
    else {
        options.clientX = options.pointerX;
        options.clientY = options.pointerY;
        var evt = document.createEventObject();
        oEvent = extend(evt, options);
        element.fireEvent('on' + eventName, oEvent);
    }
    return element;
    

    }

    function extend(destination, source) {
    for (var property in source)
    destination[property] = source[property];
    return destination;
    }

    var eventMatchers = {
    ‘HTMLEvents’: /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
    ‘MouseEvents’: /^(?:click|dblclick|mouse(?:down|up|over|move|out))$/
    };

    var defaultOptions = {
    pointerX: 0,
    pointerY: 0,
    button: 0,
    ctrlKey: false,
    altKey: false,
    shiftKey: false,
    metaKey: false,
    bubbles: true,
    cancelable: true
    };

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

Sidebar

Related Questions

We have an ascx custom control (not a web part) hosted in a special
I have a web control with some custom javascript. The javascript creates new file
I have created a custom web control to act as a button with an
I have a my own custom web server control. I created separate CSS file
We have a custom PHP/MySQL web application that gets updated and copied (using SFTP)
I have a custom Sharepoint 2010 web part that runs the user through a
I have a question about creating and managing events inside an ascx custom web
I have a custom control which inherits from System.Web.UI.Control and some of its properties
I have created a web custom control and used within an aspx page. I
I'm attempting to create a custom control that inherits from System.Web.UI.WebControls.ListView . Codebehind: using

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.