简体   繁体   English

从HiddenField asp.net绑定值

[英]Bind value from HiddenField asp.net

I need to bind the value of a HiddenField control in the .aspx page to pass it along as a parameter for a stored procedure. 我需要在.aspx页中绑定HiddenField控件的值,以将其作为存储过程的参数传递。 The value will contain a Session variable value. 该值将包含一个会话变量值。

For a normal TextBox I do: 对于普通的TextBox我可以:

<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />

For the HiddenField I would do something in the same way so I can somehow use Bind("UserID") and retrieve the value for it via the Session variable. 对于HiddenField,我将以相同的方式执行操作,以便可以使用Bind(“ UserID”)并通过Session变量检索其值。

How could this be done? 怎么办呢?

You don't need to store the variable in a hidden field if it's already in a session variable. 如果变量已经在会话变量中,则无需将其存储在隐藏字段中。

Please take a look at this article for the correct way to use session state in asp.net: 请查看本文,了解在asp.net中使用会话状态的正确方法:

http://msdn.microsoft.com/en-us/library/ms178581.aspx http://msdn.microsoft.com/en-us/library/ms178581.aspx

You can use this class to get the needed session value from your class 您可以使用此类从类中获取所需的会话值

Public Class Sessions

Public Shared Function GetValueOfSession(ByVal SessionName As String)
    If HttpContext.Current.Session(SessionName) Is Nothing Then
        Return Nothing
    Else
        Return HttpContext.Current.Session(SessionName).ToString
    End If
End Function

End Class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM