【问题标题】:How to add value in Input element using C# code in Aspx page?如何在 Aspx 页面中使用 C# 代码在 Input 元素中添加值?
【发布时间】:2018-07-14 08:48:53
【问题描述】:

如果会话变量的值不为空,我想在input 元素中添加值

<input id="sessionInput" type="hidden" value='<%# Session["UserLogin"] != null ? Session["UserLogin"].ToString() : ""; %>' />

但它不起作用。

错误

) 预期

【问题讨论】:

    标签: asp.net session master-pages


    【解决方案1】:

    最后有一个分号。使用绑定表达式时不需要这些。

    <input id="sessionInput" type="hidden" value='<%# Session["UserLogin"] != null ? Session["UserLogin"].ToString() : "" %>' />
    

    如果您希望将值绑定到输入,则必须在页面加载中调用 DataBind();

    【讨论】:

      【解决方案2】:

      使用较新的: 对值进行 html 编码。

      <input id="sessionInput" type="hidden" value='<%: Session["UserLogin"] %>' />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-08-30
        • 2017-07-30
        • 1970-01-01
        • 2013-09-07
        • 1970-01-01
        • 2011-03-15
        • 1970-01-01
        相关资源
        最近更新 更多