当我点击gridview列数据(按钮)时,如何在代码中使用javascript警报消息? [英] How to use javascript alert message in code behind when I click gridview Column data(button)?

查看:74
本文介绍了当我点击gridview列数据(按钮)时,如何在代码中使用javascript警报消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,



当我点击gridview列数据(即按钮)时如何在代码中使用javascript警告消息?



此代码通常在c#页面中工作,



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,

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



但是当我点击gridview数据或记录它不显示时。



请帮帮我,如何显示,当我点击gridview按钮



by Mohan。


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

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

by Mohan.

推荐答案

OnClientClick 按钮事件上调用js函数。



eg

如果gridview中的按钮是这样的,



Call a js function on OnClientClick event of button.

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

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





你可以看到js函数调用delrecord()就好了,





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

function delrecord() {
    if (confirm("Are you sure want to Delete Record ?")) {
        return true;
    }
    else {
        return false;
    }
}


您可以使用

you can use as
ScriptManager.RegisterStartupScript(
       this,
       typeof(Page),
       "Alert",
       "<script>alert('" + sMessage + "');</script>",
       false);







on button onclick event.


ClientScript.RegisterStartupScript(Me.GetType (),警报,警报('成功保存记录');,真实)
ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('Record Saved Successfully');", True)


这篇关于当我点击gridview列数据(按钮)时,如何在代码中使用javascript警报消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆