开发者

Eval ViewState value on a server control tag?

Is there a way to Eval the ViewState value on a server contro开发者_开发技巧l tag?

<asp:TextBox    Text='<%#Eval(Viewstate["key"])%>' runat='server' />

Thanks.


Just add a watch for that ViewState value, or set a breakpoint and use the Immediate Window.


edit Changed answer to better suit your requirement to set visibility on a control.

Sticking a databind() in the code behind after setting the Viewstate value will work. e.g.

aspx.cs : -

protected void Page_Load(object sender, EventArgs e)
{

    ViewState["Test"] = "hello";
    DataBind();
}

aspx : -

<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtHello" runat="server" visible='<%#  ViewState["Test"].ToString()    == "hello"  %>' Text="Show Hello"></asp:TextBox>
</div>
</form>
</body>

will "show hello" but if you change the viewstate value to something else it won't.


You can do it like this:

<asp:Label runat="server" Text='<%# ViewState["key"] %>'/>

The <%# %> annotation means whatever is within provides access to codebehind. In this case, it will access ViewState and retrieve the item saved under "key". As a result, the @Text of the label will be whatever the value of ViewState["key"] is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜