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.

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.