Page:
<div id='PlaceHolder' runat='server'></div>
<script type="text/javascript">
$('.className').on('click', function (event) {
event.stopPropagation();
event.stopImmediatePropagation();
$.ajax({
type: "POST",
url: "DesirePage.aspx/DesireMethod",
data: '{object: "' + this.id + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response.d) {
window.location = (response.d).ToString();
}
else {
alert('Not Successfull');
}
},
failure: function (response) {
alert('Failed');
}
});
});
</script>
Code Behind:
public static void Test()
{
Button btn = new Button();
btn.ID = empRow[0].ToString().Trim();
btn.Text = "click here";
btn.Attributes.Add("class", "className");
StringBuilder sb = new StringBuilder();
StringWriter writer = new StringWriter(sb);
HtmlTextWriter htmlWriter = new HtmlTextWriter(writer);
cloneButton.RenderControl(htmlWriter);
PlaceHolder.InnetHtml = sb.ToString();
}
[System.Web.Services.WebMethod]
public static object DesireMethod (object input)
{
// do some operation and return result
}
<div id='PlaceHolder' runat='server'></div>
<script type="text/javascript">
$('.className').on('click', function (event) {
event.stopPropagation();
event.stopImmediatePropagation();
$.ajax({
type: "POST",
url: "DesirePage.aspx/DesireMethod",
data: '{object: "' + this.id + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response.d) {
window.location = (response.d).ToString();
}
else {
alert('Not Successfull');
}
},
failure: function (response) {
alert('Failed');
}
});
});
</script>
Code Behind:
public static void Test()
{
Button btn = new Button();
btn.ID = empRow[0].ToString().Trim();
btn.Text = "click here";
btn.Attributes.Add("class", "className");
StringBuilder sb = new StringBuilder();
StringWriter writer = new StringWriter(sb);
HtmlTextWriter htmlWriter = new HtmlTextWriter(writer);
cloneButton.RenderControl(htmlWriter);
PlaceHolder.InnetHtml = sb.ToString();
}
[System.Web.Services.WebMethod]
public static object DesireMethod (object input)
{
// do some operation and return result
}