Solved

How to change the display between two image buttons based on the javascript validation?

Posted on 2008-10-17
6
236 Views
Last Modified: 2012-05-05
I have two image buttons. One is shown as enabled and the other one is shown as disabled. But only one will be shown at a time.
I need to show these buttons based on a javascript validation. By default disable button will be shown.
The validation is that on entering 5 characters into a textbox the button will be changed to enable button.
It is basically switching between image buttons based on a javascript validation.

Any help is greatly appreciated!
Thank you
0
Comment
Question by:ipjyo
  • 3
  • 2
6 Comments
 
LVL 9

Assisted Solution

by:vavjeeva
vavjeeva earned 100 total points
ID: 22746954
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22747937
>> By default disable button will be shown.
How do you hide the "enabled" button by default? Visible=False?
0
 

Author Comment

by:ipjyo
ID: 22748079
yes, I am using Visible=False property for the enable button. I need to show this button in place of the default disable button on javascript validation. Can we use place holder in this case so I can show these buttons at the same place on the screen?

thanks!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Accepted Solution

by:
prairiedog earned 400 total points
ID: 22748979
Well, if you set Visible=False, then the button will not be rendered on the page at all, and JavaScript will not be able to find it. So you can't use JavaScript to find it because it is not there. Run you application to load the page, then view Page Source of the page, you will find that there is only one button generated: the "disable" button.

What you can do is: instead of setting Visible=False for the enable button, you add a style on the image button: <div id="divEnable style="display:none"><asp:ImageButton ID="enableButton" runat="server" ></imageButton></div>
For disable button, you can do the similar thing: <div id="divDisable" style="display:block"><ImageButton ID="disableButton" runat="server"></ImageButton></div>

The JavaScript function will be:
<script language="JavaScript" type="text/javascript">
     function enableDisableButton()
     {
          var txt = document.getElementById('<%=TextBox1.ClientID%>');
          if (txt.value.length >=5)
          {
               document.getElementById('divEnable').style.display="block";
               document.getElementById('divDisable').style.display = "none";
          }
          else
          {
              document.getElementById('divEnable').style.display="none";
              document.getElementById('divDisable').style.display="block";
          }
     }

</script>

The TextBox will something like this:
<asp:TextBox ID="TextBox1" runat="server" onkeyup="enableDisableButton"></TextBox>
0
 

Author Comment

by:ipjyo
ID: 22749422
thanks for the solution..I will try this and let you know
0
 

Author Comment

by:ipjyo
ID: 22768768
Thank you..It worked for me..
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now