Execute JavaScript code on GridView SelectedIndexChanged event using jQuery in ASP.Net

Last Reply on May 04, 2017 06:37 AM By alya14

Posted on May 03, 2017 05:59 PM

the below code is working if I call in button OnclientClick But not working if I call in  gridview SelectedIndexChanged event

function Confirm()
{
     var confirmValue = document.createElement("INPUT");
     confirmValue.type = "hidden";
     confirmValue.name = "confirm_value";

     if (confirm("Process Staring ?"))
     {
           confirmValue.value = "Yes";
           document.forms[0].appendChild(confirmValue);
     }
     else
     {
           confirmValue.value = "No";
           document.forms[0].appendChild(confirmValue);
      }
}

Controls.Add(new LiteralControl("<script type='text/javascript'>return Confirm();</script>"));
string confirmValue = Request.Form["confirm_value"];        
if (confirmValue == "Yes")
{
     ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Yes')</script>");
          
}
else 
{
     ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('No')</script>");
}
Results 1 - 5 of 8 12
Posted on May 03, 2017 05:59 PM
Hi @alya14,
Please try the following

Fire GridView Edit Event on DropDownList SelectedIndexChanged in ASP.Net

It might help you.

Cheers Andrea.

Posted on May 04, 2017 01:44 AM

its not like ,I am calling JS but not fire


Posted on May 04, 2017 03:03 AM

Hi alya14,

You need to call your js script in code behind like below.So please refer the below code and modify as per your requirement.

C#

protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
    ClientScript.RegisterStartupScript(this.GetType(), "Pop", "Confirm();", true);
}

 


Posted on May 04, 2017 03:18 AM Modified on on May 04, 2017 03:28 AM

it's working under button click But not working correctly under

GridView1_SelectedIndexChanged event

 


Posted on May 04, 2017 03:31 AM

Hi alya14,

Will you please share your complete code with html.