Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在客户端单击按钮时使用资源文件_C#_Asp.net - Fatal编程技术网

C# 在客户端单击按钮时使用资源文件

C# 在客户端单击按钮时使用资源文件,c#,asp.net,C#,Asp.net,我想使用一个资源文件来显示在客户端单击时显示的对话框,我尝试了以下方法,但在屏幕截图中得到了结果: <asp:Button ID="editview" runat="server" Text="<%$ Resources:btnEditViewText%>" CssClass="buttonlink" OnClientClick="return confirm('&l

我想使用一个资源文件来显示在客户端单击时显示的对话框,我尝试了以下方法,但在屏幕截图中得到了结果:

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

我看到一些人建议在代码中设置此选项,但是此控件被包装在中继器中,我只能在触发
ItemCommand
事件后才能获得该控件的句柄,该事件需要确认对话框


这感觉有点像第二十二条军规,我没有主意了,有什么建议吗?

谢谢,本,这很有效

    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());
    }

这是我的代码,它的工作!但我也更喜欢代码隐藏解决方案,尤其是对于单个控件

在我的项目中,我在嵌套的中继器中使用这个方法,所以我不需要使用OnItemDataBound方法。这太容易了

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

我找到了最好的解决方案

<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()"/>

函数DeleteItem(){
if(确认(document.getElementById(“”).value)){
返回true;
}
返回false;
}

您可以在中继器的ItemDataBound事件中的代码隐藏中设置它。这对我不起作用。它使用正确的资源并显示正确的消息,但无论我单击什么-确认、取消,或者即使我只是关闭警报框-结果总是相同的,记录也会被删除。