Solved

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

Posted on 2008-10-17
6
238 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

773 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