I have a textbox.Texbox is readonly. And on Page_Load the Texbox automaticlly displayed with a value from the data base.i have a 'if' loop for check the text box value is null or not.But i cant retrive the textbox value.What may be the reason for that? my web page code is
<asp:TextBox ID = "text1" runat="server" ReadOnly="true" ></asp:TextBox>
<asp:DropDownList ID="DropDownList1" runat="server" Visible="False">
</asp:DropDownList>`
code behind
if (text1.Text == "")
{
DropDownList1.Visible = true;
}
but DropDownLi开发者_如何学JAVAst1 is not displayed
The Problem is that you cannot post back the values which are either readonly or enabled = false. You have to find out some other way to post them to server.
You may try to place a hidden input next to textbox with runat attribute set to "server" and check input's value after postback (of course you will have to fill the input with the same value as textbox). Doesn't seem a beautiful decision for me, but this will work.
This may be because your database may contain space values. So you cant compare " " with "" You just try to trim the text box value and then try to compare.
精彩评论