Call event click

1

I want to send this event with JavaScript

protected void newButton_Click(object sender, EventArgs e)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "ModalGood();", true);
            Button Btnclick = (Button)sender;
            var team = Btnclick.Text;
            string name = Btnclick.CommandArgument;

            List.ListUsers listArea = new List.ListUsers();
            List<Data.Area> Area = listArea.AreaList();

            List<Data.Area> ListOfToolsOk = Area.Where(x => x.AREA == team && x.TEAM == team && x.STANDBY == 0).ToList();

            var ToolArea = ListOfToolsOk.Select(x => x.TEAM);
            Grv_Eng.DataSource = ListOfToolsOk;
            Grv_Eng.DataBind();
        }

passing the element sender taking into account that the id of the button that executes that event is dynamic.

Is it possible to do it with JavaScript ?

    
asked by Cesar Gutierrez Davalos 05.07.2017 в 18:39
source

3 answers

1

with jquery would be:

<a class="t" id="dynamic"></a> 

$(".t").click(function(e){
  newButton_Click($(this),e)
})

if you do not want to use jquery

document.getElementsByClassName("t").addEventListener('click', function(e){
  newButton_Click(document.getElementsByClassName("t"),e)
})

The idea is that if the ID is dynamic use another attribute that is not dynamic to be able to consult the DOM

    
answered by 05.07.2017 в 18:47
0

Well, what I would do would be the following:

The button would be something like this:

<asp:Button runat="server" ID="newButton" Text="" style="display:none;" OnClick="newButton_Click" />

and in Javascript this, within the function event where you need it:

document.getElementById("btnSample").click();
    
answered by 05.07.2017 в 18:48
-1

To capture the event by passing it all the data would be as follows:

function clickHandler(e, v) {
	
  console.log(e, v);
  // e es el evento
  // v es el boton

}
<html>
  <head>
    <title> Handling click event </title>
    <meta charset="utf8">
  </head>
  <body>
    <button onclick="clickHandler(event, this)"> Click me!!! </button>
  </body>
<html>
    
answered by 23.10.2017 в 21:25