Click here to Skip to main content
15,307,242 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Friends,
I'm Having a textbox , Dropdownlist and Button in my aspx page.
When item is selected in dropdown list, I make textbox visible false by using javascript.
in Button click im doing some validation and the alert will come if there is any validation failed.

My Problem is,
When I click button the alert is working fine but the textbox is visible (true) automatically.
I never write code to make textbox visible true in aspx.cs page.
But still its happening..
How to solve this?
Please help me on this...

Here the problem is page postback

on page lode method u just check the
Its because ur page is posting back after validation

I suggest you to write visible property on your button click event like


and on page load write

protected void LinkButton1_Click(object sender, EventArgs e)
if (LinkButton1.Enabled == true)
TextBox1.Visible = true;
Button1.Visible = true;

protected void Button1_Click(object sender, EventArgs e)
if (Button1.Enabled == true)
TextBox1.Visible = false;
Its because on click of your button, the page is making a postback. If you have not done any server side coding on that button, you can write a "return false;" statement in javascript to avoid postback. Or other wise, make the textbox visible false on codebehind of that button.

[Updated point]
While calling your method on click of button put a "return" before the method name, and "return false" at the end of your javascript. This will do.
[/updated point]

I think your page gets postback when you respond to alert message.
Just give return false after your alert in Javascript.
That will stop the postback.

- Happy programming
I have added "return false;" in javascript . But still there is same problem..
@nuraGGupta@ 6-May-11 3:00am
You need to provide any additional information by editing your question only. You do not need to add a new solution here for this. (See my updated answer for this problem.)
Check Ispostback on page lode.

Take one hidden field set value using js when user click on drop down list box set it to true.(set default value false)
and on page lode evet check that hidden value field if its value is false then not view your text box.
write the code set visible(false) of textbox during postback, so that every time u click on the button textbox ll b invisible..k

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