代码之家  ›  专栏  ›  技术社区  ›  Liam neesan

如何在aspx页面中使用c代码在输入元素中增加值?

  •  0
  • Liam neesan  · 技术社区  · 6 年前

    我想增加价值 input 元素,如果会话变量的值不为空

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

    但它不起作用。

    错误

    )预期的

    2 回复  |  直到 6 年前
        1
  •  0
  •   VDWWD    6 年前

    你在结尾有一个分号。当使用绑定表达式时,这些是不需要的。

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

    你必须打电话 DataBind(); 如果要将值绑定到输入,请在页面中加载。

        2
  •  0
  •   wazz    6 年前

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

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