Click here to Skip to main content
15,904,288 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi friends,

can you please help me. am using ASP.NET, C#, SqlServer

I have a textbox label and a submit button on webpage.

If i enter anything text in textbox..., In label it must display YES
if i left textbox empty the label must display blank

can you please help me.

Thanks in advance...
Posted

hello ranjith

here is my explanation

ASP.NET
<asp:textbox onkeyup="return getbinded();" xmlns:asp="#unknown" ></textbox>


javascript function

JavaScript
<script type="text/javascript">
function getbinded()
{
if(document.getelementbyid('txtboxid').text.length>0)
{
   document.getelementbyid('labelid').innertext='yes'
}
else
{
   document.getelementbyid('labelid').innertext='';
}
}
window.onload=getbinded()
</script>


hope this will help you :)
 
Share this answer
 
v2
Comments
Ganesh Prakash 1-Aug-13 5:19am    
I suggest that you add the onKeyUp property to the TextBox instead of Button. That way, the user will be able to view changes to label without clicking the submit button.
Dholakiya Ankit 1-Aug-13 5:21am    
oh yes
try this

C#
if (textbox1.text.length == 0)
{
label1.text="No";
}
else
{
label1.text="Yes";
}


Is this is what you wanted..??
 
Share this answer
 
Comments
Ranjith Reddy CSE 1-Aug-13 5:33am    
acutally, the textbox is in gridview footer. so how can i write code for footer textboxe in gridview.
[no name] 1-Aug-13 7:27am    
That you should mention in your question.we can't see your application from here..
Try this.
XML
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="textboxchanged" AutoPostBack="true"></asp:TextBox>
  <asp:Label ID="lbl" runat="server" Text="No"></asp:Label>




C#
protected void textboxchanged(Object sender, EventArgs e)
 {
     if (TextBox1.Text != "")
     {
         lbl.Text = "Yes";
     }
     else { lbl.Text = "No"; }
 }
 
Share this answer
 
Comments
Ranjith Reddy CSE 1-Aug-13 5:33am    
acutally, the textbox is in gridview footer. so how can i write code for footer textbox in gridview.
Vandana_Pathak 1-Aug-13 7:41am    
<asp:Label ID="lbl" runat="server" Text="No">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true" OnRowDataBound="CustomersGridView_RowDataBound" ShowFooter="true">
<columns>
<asp:BoundField DataField="amt" HeaderText="Amt"/>
<asp:TemplateField>
<footertemplate>
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="textboxchanged" AutoPostBack="true">






DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
dt.Columns.Add("amt", typeof(Int32));
dt.Columns.Add("pamt", typeof(Int32));
dt.Columns.Add("damt", typeof(Int32));
DataRow dr=dt.NewRow();
dr[0] = 200;
dt.Rows.Add(dr);
DataRow dr1 = dt.NewRow();
dr1[0] = 400;
dt.Rows.Add(dr1);
GridView1.DataSource = dt;
GridView1.DataBind();
string directoryPath = @"D:\New folder";
TextBox TextBox1 = (TextBox)GridView1.FooterRow.Cells[0].FindControl("TextBox1");
TextBox1.Text = "abc";
}
}

protected void textboxchanged(Object sender, EventArgs e)
{
TextBox TextBox1 = (TextBox)GridView1.FooterRow.Cells[0].FindControl("TextBox1");
if (TextBox1.Text != "")
{
lbl.Text = "Yes";
}
else { lbl.Text = "No"; }
}
Try this may be it is helpful for you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900