checking hidden field is empty or not
i开发者_运维问答 have a
<asp:HiddenField runat="server" ID="ListTwoHiddenField" />
i have some programming aspect how can i check whether hidden field is empty or not
i mean i want to check that ListTwiHiddenField.items.cout==0
or empty how can i check this
HiddenFields don't have an Items collection, they just have a Value property, which is a String. So to check if it's empty all you need is:
if (string.IsNullOrEmpty(ListTwoHiddenField.Value)
{
}
Or you could use string.IsEmptyOrWhitespace
, which would check whether the hidden field's value is just [space] characters.
dont check for NUll and Empty in one line
like this
if(HiddenObj.Value != null || HiddenObj.Value.Length > 0)
{
//hidden object is not null and have length more than zero that means have some content
}
else
{
//hidden object is null or have length empty
}
this thing is going to fail
try like this
if(HiddenObj.Value != null)
{
if(HiddenObj.Value.Length > 0)
{
//hidden object is not null and have length more than zero that means have some content
}else
{
// hidden object value is empty
}
}else
{
// hidden object is Null
}
// from santosh kakani
you just need to check :
if(ListTwoHiddenField.Value != String.Empty)
{
//do code
}
No need for checking null also. if you are adding hidden field to aspx page. when page controls initialize itself it will also initialize.
精彩评论