Postback Problem

  • Thread starter Thread starter Amy Snyder
  • Start date Start date
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?
 
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
 
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?
 
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
 
Back
Top