Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Sir,

How to use javascript alert message in code behind when I click gridview Column data(ie. Button)?

This code normally Working in c# page,

XML
ScriptManager.RegisterStartupScript(Page, this.GetType(), "AlertMessage", "<script language=\"javascript\"  type=\"text/javascript\">;alert('Mohan');</script>", false);

But when I Click gridview data or record its not display.

Please Help me, How to display, when I click gridview button

by Mohan.
Posted
Updated 30-Jan-17 0:44am
v2

Call a js function on OnClientClick event of button.

e.g.
if the button in gridview is like,

XML
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImageButton3" runat="server" CommandName="Delete" Height="12px"
ImageUrl="~/images/delete.png" ToolTip="Delete Record" Width="12px" OnClientClick="return delrecord();" />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" Wrap="False" Width="30px" />
<ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Wrap="False" Width="30px" />
</asp:TemplateField>


as you can see js function delrecord() is called which is like,

C#
function delrecord() {
    if (confirm("Are you sure want to Delete Record ?")) {
        return true;
    }
    else {
        return false;
    }
}
 
Share this answer
 
v2
you can use as
C#
ScriptManager.RegisterStartupScript(
       this,
       typeof(Page),
       "Alert",
       "<script>alert('" + sMessage + "');</script>",
       false);


on button onclick event.
 
Share this answer
 
ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('Record Saved Successfully');", True)
 
Share this answer
 
Comments
CHill60 30-Jan-17 7:12am    
The question was resolved 5 years ago. Your single line of "solution" contradicts the accepted answers without any explanation at all. Pointless.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900