Call Javascript function from Gridview RowDeleting

2019-08-14 05:08发布

问题:

I need to call a javascript alert from an if condition inside a gridview in the gvLocations_RowDeleting section.

Code is as follows:

protected void gvLocations_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    if (CheckIfLocationExists(ID) == true)
    {
        //need to call javascript function sendmessage() here?? 
    }
}

I have a javascript function in the .aspx file as follows

<script type="text/javascript">
function sendmessage()
{
    alert("Area is associated with this location already");
}
</script>

I know this is an easy move but for some reason Im having trouble. Can someone help? thanks in advance. Stack Overflow rocks!

回答1:

Actually I figured it out. Hopefully this will help someone else..Use the code below, works like a charm..

Page.ClientScript.RegisterStartupScript(this.GetType(), "helloworldpopup", "alert('hello world');", true);