0

Please all,

I am currently working on a web application which i must submit as soon as possible.

I have a button and a text box. What i want is that if the textbox is empty, the button should be invisible.
Immediately the user starts typing in the text the button should be visible without leaving the textbox itself. I have used postback = true but not until i press the tab key before the code is executed.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Geekitygeek
0

Rather than perform a postback every time the text changes, you can use Javascript locally to change the buttons visiblity whenever a key is pressed in textbox:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TextBox1.Attributes.Add("onKeyUp", "ChangeButton()")
    End Sub

then your javascript in page looks like:

<div>
            <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
            <script type="text/javascript">   
                function ChangeButton() {   
                    var content = document.getElementById('TextBox1').value;
                    if(content.length>0)
                    {
                        document.getElementById('Button1').style.visibility = 'visible';
                    }  
                    else
                    {
                        document.getElementById('Button1').style.visibility = 'hidden';
                
                    }
                }   
        </script>  
            <asp:Button ID="Button1" runat="server" Text="Button" />
        </div>

Hope that helps :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.