Interact with a LinkButton using JavaScript on Internet Explorer 9

My Repeater contains multiple LinkButtons that perform a postback when manually clicked. However, my attempts to trigger the click event on a LinkButton using JavaScript have been unsuccessful. I have tried both OnClick and OnCommand without any luck.

LinkButtons:

<asp:Repeater ID="repItems" runat="server" OnItemDataBound="repItems_OnItemDataBound">
    <ItemTemplate>
        <asp:Panel ID="pnlItem" runat="server">                       
            <asp:LinkButton ID="lnkItem" runat="server" OnClick="lnkItem_OnClick" OnCommand="lnkItem_OnCommand"></asp:LinkButton>                  
        </asp:Panel>
    </ItemTemplate>        
</asp:Repeater>  

Javascript:

eval(LinkButton.attr('href'); //Causes Sys.ParameterCountException
LinkButton.click();           //Nothing happens (no click event on LinkButton)
LinkButton.trigger('click');  //Same as LinkButton.click()

If I set OnClientClick to initiate the postback, the click() functions start working, but it triggers a Sys.ParameterCountException error:

lnkItem.OnClientClick = String.Format("__doPostBack('{0}', '');", lnkItem.UniqueID);

Some suggestions included changing ScriptManager to release mode, but it did not trigger the postback, only removed the error message.

The eval(LinkButton.attr('href'); function works in Google Chrome.

Answer №1

I'm uncertain about the issue you may be facing, but I have a solution that works for me.

ASCX:

<asp:Repeater ID="repItems" runat="server">
    <ItemTemplate>
        <asp:Panel ID="pnlItem" runat="server">                       
            <asp:LinkButton ID="lnkItem" runat="server" Text='<%# Eval("Text") %>' OnClick="lnkItem_OnClick" OnCommand="lnkItem_OnCommand"></asp:LinkButton>                  
        </asp:Panel>
    </ItemTemplate>        
</asp:Repeater>

<button onclick="document.getElementById('MainContent_repItems_lnkItem_0').click(); return false;">Huzzah!</button>

Codebehind:

    protected void Page_Load(object sender, EventArgs e)
    {
        List<Item> test = new List<Item>();
        test.Add(new Item { Text = "Item 1" } );
        test.Add(new Item { Text = "Item 2" } );
        repItems.DataSource = test;
        repItems.DataBind();
    }

    protected void lnkItem_OnClick(object sender, EventArgs e)
    {
        this.Controls.Add(new Literal() { Text = ((LinkButton)sender).Text });
    }

    protected void lnkItem_OnCommand(object sender, EventArgs e)
    {
        this.Controls.Add(new Literal() { Text = ((LinkButton)sender).Text });
    }

In this example, both OnClick and OnCommand events are triggered successfully.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What sets apart the method of assigning event handlers using bind() versus each() in jQuery?

Could someone explain the difference between using bind() to assign event handlers and using each() for the same task? $(function () { $('someElement') .bind('mouseover', function (e) { $(this).css({ ...

Navigating a dynamic table by looping through its generated tr elements

I am currently working with a dynamically created tr table that includes individual rows of data and a fixed total sum at the bottom. The total sum does not change dynamically. var tmp = '<tr id="mytable"> <td id="warenid">'+data1.id ...

Exposing the full binary in jQuery

Can anyone explain how jQuery can display the entire binary representation of a number without removing the leading zeros? Here is the code snippet: HTML: <input id="input" type="text" size="20"> <input id="result" type="text" size="30"> < ...

Solving data within an Angular Controller

Recently delving into Angular development, I've found myself caught in a loop trying to solve this particular issue. To give some context, I'm utilizing the MEAN stack through mean.io which includes Angular UI Router functionalities. In my data ...

Generate a novel item by organizing the key of an array of objects

I have an array of objects containing various items: [ { CATEGORY:"Fruits" ITEM_AVAIL:true ITEM_NAME:"Apple" ITEM_PRICE:100 ITEM_UNIT:"per_kg" ITEM_UPDATED:Object ORDER_COUNT:0 }, { CATEG ...

Is it possible to compare every element in an array with one another using an asynchronous process in NodeJS?

I am currently utilizing Resemble.js for image comparison within my web application. I have an array of image URLs that I need to compare with each other in order to calculate a unique score for each image. For example: [url1, url2, url3, url4] The minimu ...

How to set the element in the render method in Backbone?

Currently, I am in the process of developing a web page utilizing BackboneJS. The structure of the HTML page consists of two divs acting as columns where each item is supposed to be displayed in either the first or second column. However, I am facing an is ...

Guide to connecting two geometric shapes together with the help of three.js

Is there a way to link two spheres together with a line? I'm looking for a solution that mimics two balls connected by a rope or something elastic. Does anyone have any examples to share? ...

What is the correct way to properly import a non-relative path in TypeScript?

Struggling with importing into my TypeScript class. // Issue arises here... import * as Foundation from 'foundation/foundation'; // Everything runs smoothly until the above import is added... export class HelloWorldScene { constructor() { ...

Converting jQuery drag and drop functionality to Angular: A step-by-step guide

I have implemented drag and drop functionality using jquery and jquery-ui within an angular project. Below is the code structure: Index.html, <!doctype html> <html lang="en"> <head> <link href="//code.jquery.com/ui/1.10.3/themes/ ...

utilizing a spacemouse in conjunction with autodesk forge

Recently, I acquired a 3dconnexion spacemouse and have been attempting to configure it to work with the forge viewer. Fortunately, I came across some JS samples in the SDK for three.js that worked flawlessly. It seems both forge and three.js utilize webgl ...

Ways to inspect a number within a span and adjust its color depending on the value?

Can someone help me figure out why this code is not reading the value correctly? Check it out here This is the HTML: <a class="InterestLink">Click me</a> <div id="InterestExpander"> <div id="InterestExpanderX"> ...

Angular 2 Encounter Error When Trying to Access Undefined Property in a Function

Element: import { Component, OnInit } from '@angular/core'; import { HttpClient } from '@angular/common/http'; @Component({ selector: 'app-ore-table', templateUrl: './ore-table.component.html', styleUrls: [&a ...

Ways to standardize the input email address?

While using express-validator, I came across an issue where I used normalize email for validation of email during sign up and stored the normalized email on the server. Validation code: router.post( "/signup", [ check("name").n ...

Troubles with a Chrome Extension for JSON

I'm currently working on a project to develop a Google Chrome extension and I've encountered an obstacle. I'm experimenting with JSON data (with the intention of integrating it with an API in the future). I have a sample JSON file, successfu ...

Iterating through a C# list in JavaScript

My current situation involves having a list structured in the following way: List<string> list = new List<string>(10); list.Add("Foo"); list.Add("Bar"); list.Add("Tord"); list.Add("Bob"); I am inquiring about the process of looping through t ...

I am facing an issue where my AngularJS code is not executing properly on JSF

I'm trying to clear the text inside a textarea using AngularJS after typing and clicking on a button. Here's the link to the fiddle for reference: http://jsfiddle.net/aman2690/2Ljrp54q/10/ However, I keep encountering the following error messag ...

Using Node.js to integrate Stripe payment method

After successfully implementing a stripe payment method with node and express, I encountered some issues. Although the payment runs smoothly and returns a success message, the customer is not being added to the list of stripe customers. Additionally, my no ...

Transform one column into several columns

I am working with a function that populates a table row by row. Here is the code: function renderListSelecoes(data) { // JAX-RS serializes an empty list as null, and a 'collection of one' as an object (not an 'array of one') va ...

Implement a new aggregate function for tooltips in the Kendo chart

I am currently utilizing a kendo chart with a date x-axis. Each point on the graph corresponds to different dates, but the x-axis displays only a monthly view. To showcase the last data point for each month, I have implemented a custom aggregate function a ...