Saturday, March 31, 2012

Text Box and submit button not visible on the browser

Hi,
I am new to this group and to ASP.Net. I wrote a simple .aspx program in VS.Net environment. It has a label control, TextBox control and a button control. When the page is viewed on the browser, one enters their name or whatever and click the submit button, the resulting page shoul display "Hello and the text from the text box. I added required code in the button click event. The problem is when the page is loaded first time on the browser, I see only the label contol with the text that I entered before. Text Box and the Button controls are not visible. Any clues??
thanks.do you have runat=server for both?
Make sure that you have runat="server" in the html for the textbox and button...and make sure you have not set the visible property to false

MajorCats
I do have runat="server" and the Visible properties are set to False. Still it is not working. any other clues?...
After playing around with the code, I realized that none of my web controls are visible in the browser. If I change the following code
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
to
<input type="text" id="TextBox1"> </input>
then, I see the text box.
But it is not useful when I am trying to build a page using the web controls.
Why is it none of my web controls are visible?.
Anyone know what is triggering this kind of behavior?
help please...... :(
..."and the Visible properties are set to False."

I am assuming you meant that the visible property is NOT set to false...or this is your problem.

Post your html and code...

MajorCats
Here is the code... None of my web controls are visible when loaded in the browser. When I change them to a normal <input> tag, then it displays. It is not useful, when I am trying to develop a web application in the .Net environment. Text box property is set to Tru to begin with and then changed later in the code. see the button_click event handler code. Any help is appreciated.
thanks.

Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = "Hello. " & TextBox1.Text & "!"
TextBox1.Visible = False
Button1.Visible = False
End Sub
End Class

<%@. Page Language="vb" AutoEventWireup="false" Codebehind="Hello.aspx.vb" Inherits="Aerosea.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<P>
<asp:Label id="Label1" runat="server">Enter a Name:</asp:Label>
<asp:TextBox id="TextBox1" runat="server" Visible="False"></asp:TextBox>
<asp:Button id="Button1" runat="server" Text="Submit" Visible="False"></asp:Button></P>
</form>
</body>
</HTML
Your problem is the visible=false in your tag...

<asp:TextBox id="TextBox1" runat="server" Visible="False"></asp:TextBox
Change this to:

<asp:TextBox id="TextBox1" runat="server" Visible="True"></asp:TextBox
and it will show up.

Basically, your code shows that you are hiding your textbox and button, and if the button were visible and someone clicked it, you are hiding it yet again......

MajorCats
Thank you very much. I totally overlooked the HTML part and thought the problem was in the Code. I changed it, and now it works.
thanks.

0 comments:

Post a Comment