Postback Problem

A

Amy Snyder

I have a webform that has a listbox and two textboxes. The style
property of the text boxes are:

style="DISPLAY: none"

Based on the selection made in the listbox, one or both textboxes are
displayed using javascript. The problem comes when I submit the form.
I want the text boxes to stay displayed after submitting the form
because there will be values in them. How can I do this with .NET /
JavaScript?
 
S

S. Justin Gengo

Amy,

First a quick question. Do you still want the form to post back? If you do
then you don't need to use javascript at all. You can just set the text
box's visible property (not the style) to false and then when the page posts
back to the server check the drop down's value and based on that set the
necessary text box's visible property to true.

If you want to do this without posting back to the server then you'll want
to create a javascript that checks the drop down's value and resets the text
box's style tags appropriately.

To get you started, if the second scenario is what you need, I have some
javascript sample code in the code library of my web site,
www.aboutfortunate.com, that you might find helpful.

Just go to the site and then click the code library link. There is a search
box that you can use to find this sample:

Open web page from drop down list

It will show you how to use javascript to get the value selected in your
drop down list.

I don't have a sample for controlling the style tag of your text boxes but a
google search should turn up many.


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
A

Amy Snyder

I don't want to postback after selecting the listbox item. After
selecting the listbox item, one or both text boxes appear - I have that
working fine.

The postback is the problem. Because my style.display is initially set
to 'none' for all textboxes, after the postback all textboxes will be
hidden. I need the textboxes that were visible prior to posting to be
visible after posting. Make sense?
 
S

S. Justin Gengo

Amy,

After postback either clear or change the text boxes style attributes from
the code-behind page like this:

TextBox1.Attributes.Clear()

or

TextBox1.Attributes.Add("style", "[your style here]")

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top