zoukankan      html  css  js  c++  java
  • ASP.NET小技巧:使用Escape解決但双引号引发的问题。

    一:先看个下面2个列子来引出问题

    1.<input type="button"   onclick="javascript:popupWindowRefresh(510,'MessageBox.aspx?oid=<%#Eval("Id")%>&comment=<%#Eval("OrderComment")%>')"  value="留言" class="offWhiteBtn" />

    2.<input type="button"  ID="MessageButton" runat="server" onclick="javascript:popupWindowRefresh(510,'MessageBox.aspx?oid=<%#Eval("Id")%>&comment=<%#Eval("OrderComment")%>')"
                                        value="留言" class="offWhiteBtn" />

    第一个例子和第二个列子几乎相同唯一不同的是第二个是加了runat="server" 成为服务器标记。第一个例子可以编译通过,第二个无法编译同过,报什么“The server tag is not well formed.”的错误。

    二:解决方案

    不管是不是runat=server都是最外加单引号,里面用用双引号,如果里面还是要用字符串引号的话就用"\""可以解决。这个方案上面2种情况都可以用。

    <input type="button"  ID="MessageButton" runat="server" onclick='<%#"javascript:popupWindowRefresh(500,"+"\""+string.Format("MessageBox.aspx?oid={0}&comment={1}",Eval("Id").ToString(),Eval("OrderComment").ToString())+"\""+")"%>'
    value="留言" class="coffeeText" />

  • 相关阅读:
    亲和数
    改革春风吹满地
    处理选中图片
    项目架构(结构)搭建:主流结构(UITabBarController + 导航控制器)
    iOS应用启动main函数
    LaunchScreen&LaunchImage
    颜色常识
    折半查找法(二分法)
    冒泡排序
    多用户登录
  • 原文地址:https://www.cnblogs.com/scottpei/p/2382307.html
Copyright © 2011-2022 走看看