Click here to Skip to main content
Sign Up to vote bad
good
See more: ASP.NET
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.
And,
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...
Posted 5 May '11 - 19:57


8 solutions

hi
 
Here the problem is page postback
 
on page lode method u just check the
is(!page.postback)
textbox.visible=false;
  Permalink  
Its because ur page is posting back after validation
 
I suggest you to write visible property on your button click event like
 
textbox.visible=false;
 
and on page load write
 
textbox.visible=true;
  Permalink  
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;
}
}
  Permalink  
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]
 

Anurag
  Permalink  
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
  Permalink  
Hi,
I have added "return false;" in javascript . But still there is same problem..
  Permalink  
Comments
@nuraGGupt@ - 6 May '11 - 3:00
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.
  Permalink  
write the code set visible(false) of textbox during postback, so that every time u click on the button textbox ll b invisible..k
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 216
1 Sergey Alexandrovich Kryukov 169
2 Tadit Dash 154
3 Richard MacCutchan 145
4 Santhosh G_ 125
0 Sergey Alexandrovich Kryukov 10,338
1 OriginalGriff 7,965
2 CPallini 4,201
3 Rohan Leuva 3,522
4 Maciej Los 3,159


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 2 Jul 2011
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid