在OnClientClick按钮上使用资源文件

时间:2014-10-29 14:51:06

标签: c# asp.net

我想使用资源文件显示客户端点击时显示的对话框,我已经尝试了下面但是我在屏幕截图中得到了结果:

               <asp:Button ID="editview" runat="server" Text="<%$ Resources:btnEditViewText%>"  CssClass="buttonlink"                         
               OnClientClick="return confirm('<%$ Resources:btnEditViewText%>');"
               CommandName="editview" 
               CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Id")%>'/>

enter image description here

我见过一些人建议在后面的代码中设置这个,但是这个控件包含在一个转发器中,一旦ItemCommand事件被触发需要确认对话框,我只能处理它已经确认。

这感觉就像是一个吸引力22,我的想法,任何建议家伙?

3 个答案:

答案 0 :(得分:1)

谢谢Ben,这很有用

    protected void rptVessels_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Button button = (Button)e.Item.FindControl("editview");
        button.OnClientClick = String.Format("return confirm('{0}')", GetLocalResourceObject("alertEditVesselText").ToString());
    }

答案 1 :(得分:0)

这是我的代码,它有效!但我也更喜欢解决方案背后的代码,尤其是单控制。

在我的项目中,我在嵌套转发器中使用它,因此我不需要使用OnItemDataBound方法。它很容易......

OnClientClick='<%#String.Concat("if ( !confirm(\u0027", Resources.Resource.AreYouSureToDelete, "\u0027)) return false;") %>'

答案 2 :(得分:-1)

我找到了最佳解决方案

<script type="text/javascript">
    function DeleteItem() {
        if (confirm(document.getElementById('<%=hdelete.ClientID%>').value)) {
            return true;
        }
        return false;
    }
 </script>

 <asp:HiddenField runat="server" ID="hdelete" Value="<%$Resources:Resources, Confiemdelete %>" />
 <asp:Button ID="btnmergewithname" runat="server"  Text="<%$Resources:Resources, Delete %>" OnClientClick="return DeleteItem()"/>