", item["Title"], "</a> In aspx page: Add script to get selected anchor tag item ID and Tiltle .Save" /> ", item["Title"], "</a> In aspx page: Add script to get selected anchor tag item ID and Tiltle .Save" />

Programmatically Trigger button onclick for dynamically created controls

This tutorial, we will discuss how to trigger button onclick programmatically for dynamic created controls.

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;
}

You may like following javascript tutorials:

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

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

jayabharathi

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

>