Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a textbox at run time or hide/unhide a text box

Status
Not open for further replies.

theresatan

Programmer
Mar 18, 2002
101
US
Hi, all

Does a page can do this?

When user's input = Yes then pop up a textbox and let user fill in the reason in it.

When user's input = No, then exit.

My question are:

1. How to create a textbox at run time or

2. Textbox created on design time but by default it is not visible. when button on click, then textbox is visible.

I try following but it didn't work.

<html>
<script runat=&quot;server&quot;>

Sub Submit_Click(Sender As Object, E As EventArgs)
textbox1.visible = &quot;true&quot;
End Sub
</script>

<body bgcolor =&quot;Beige&quot;>
<form runat=&quot;server&quot;>

<asp:textbox id=&quot;textbox1&quot; text =&quot;hello&quot; visible = &quot;false&quot; width =100px runat=&quot;server&quot;/>
<asp:button text=&quot;Submit&quot; id=&quot;Submit&quot; runat=&quot;server&quot;/>

</form>
</body>
</html>

Your input is appreciated.

Theressa
 
Try this Theresa:

Add Handles Submit.Click
after the
Sub Submit_Click(Sender as object, e as eventargs)


Jack
 
Jack,

I tried that and got 'Syntax error' on 'Handles Submit.Click'

Can you try it?
<html>
<script runat=&quot;server&quot;>

Sub Submit_Click(Sender As Object, E As EventArgs)
Handles Submit.Click
textbox1.visible = &quot;true&quot;
End Sub
</script>

<body bgcolor =&quot;Beige&quot;>
<form runat=&quot;server&quot;>

<asp:textbox id=&quot;textbox1&quot; text =&quot;hello&quot; visible = &quot;false&quot; width =100px runat=&quot;server&quot;/>
<asp:button text=&quot;Submit&quot; id=&quot;Submit&quot; onclick=&quot;Submit_Click&quot; runat=&quot;server&quot;/>

</form>
</body>
</html>


Thanks for your help!

Theresa
 
Hey Theresa,

I copied your code from the second post, and you're right: the handles submit.click won't work because it needs a WithEvents variable, which is usually declared in teh code behind. It looks like you aren't using a code behind though, so just get rid of the handles part.

Now here's the thing thoguh: that identical code, with the handles part taken out, DOES WORK on my machine.

Your first post just said that it wasn't working. Were you getting an error, or it just wasn't doing what you wanted it to?

jack
 
Jack,

When I took handles part away, it works.

Before I posted it wasn't doing what you wanted but now it is the way I want.

I guess it is because I just refreshed the page instead of completely open a new page at the very beginning.

Thank you for your help and have a great holiday weekend!

Theresa

 
I wish it was a holiday weekend (ours was last week up here in Canada, but that still means a short work week)
:)

Glad you got it working. Have a great weekend too

jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top