Programmatically Trigger button onclick for dynamic created controls


Hi Friends, Trigger button onclick for dynamic controls created programmatically.

Example: If an anchor tag is created in code behind and onclick should be trigger in code behind.

Create control in code behind(In aspx.cs page):

<a href=’#’ onclick=getDocuments(“, item[“ID”], “,'”, item[“Title”], “‘”, “)>”, item[“Title”], “</a>

In aspx page:

Add script to get selected anchor tag item ID and Tiltle .Save the values to hidden fields .

Trigger code behind onclick method from javascript.

<script type=”text/javascript”>

function getDocuments(id, requestTitle) {

document.getElementById(‘<% =hiddenRequestId.ClientID %>’).value = id;

document.getElementById(‘<% =hiddenRequestName.ClientID %>’).value = requestTitle;

document.getElementById(‘<% =btnGetDocuments.ClientID %>’).click();

}

</script>

In aspx.cs page

protected void btnGetDocuments_Click(object sender, EventArgs e)

{

//Some code;

}

This code will help to call onclick of dynamical controls created through code.

Trigger button onclick for dynamic controls created programmatically

Example: If an anchor tag is created in code behind and onclick should be trigger in code behind.

Create control in code behind(In aspx.cs page):

<a href=’#’ onclick=getDocuments(“, item[“ID”], “,'”, item[“Title”], “‘”, “)>”, item[“Title”], “</a>

In aspx page:

Add script to get selected anchor tag item ID and Tiltle .Save the values to hidden fields .

Trigger code behind onclick method from javascript.

<script type=”text/javascript”>

function getDocuments(id, requestTitle) {

document.getElementById(‘<% =hiddenRequestId.ClientID %>’).value = id;

document.getElementById(‘<% =hiddenRequestName.ClientID %>’).value = requestTitle;

document.getElementById(‘<% =btnGetDocuments.ClientID %>’).click();

}

</script>

In aspx.cs page

protected void btnGetDocuments_Click(object sender, EventArgs e)

{

//Some code;


}

This code will help to call onclick of dynamical controls created through code. Thanks for reading this article.


You May Also like the Following SharePoint Online Tutorials:

About jayabharathi

The turning point in the process of growing up is when you discover the core of strength within you that survives all hurt.

View all posts by jayabharathi →

Leave a Reply