Click here to Skip to main content
13,143,628 members (28,452 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello! i have one textbox and a label. Here my query is that whenever i"ll start writing in the textbox immediately label will show a message "This username is unavailable" or "This username is available"(textbox data will search in database for username). I've written the following code. But it's working only whenever I"m Pressing "Enter" switch in the textbox. I want that should happen without using of "Enter" switch.

I have enabled AutoPostBack=true for textbox.

Source Code:
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" CausesValidation="True" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

C# Code:
protected void TextBox1_TextChanged(object sender, EventArgs e)
            SqlCommand SqlCmd = new SqlCommand("SELECT Manufacturer FROM MOBILE WHERE Manufacturer='" + TextBox1.Text + "'", SqlCn);
            SqlDataAdapter adapter = new SqlDataAdapter(SqlCmd);
            SqlDataReader SqlDr = SqlCmd.ExecuteReader();
            if (SqlDr.Read())
                Label1.Text = "This username is unavailable.";
                Label1.Text = "This username is available";
        catch (Exception ex)
            string msg = ex.Message;
Posted 22-Apr-13 5:01am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

First write this code in your .ASPX.
<div id="divMessage" runat="server" class="" style="display: none;">
       <asp:Literal runat="server" ID="ltlMessage" Text="test"></asp:Literal>

Then just write this code behind you .CS page.
public static void ShowMessage(string _class, string msg, System.Web.UI.HtmlControls.HtmlGenericControl divMessage, Literal ltlMessage)
           divMessage.Style.Add(&quot;display&quot;, &quot;block&quot;);
           divMessage.Attributes.Add(&quot;class&quot;, _class);
           ltlMessage.Text = msg;

                   UISettings.ShowMessage("alert alert-success", "Insert Successfully", divMessage, ltlMessage);
               catch (Exception ex)
                   ShowMessage("alert alert-error", ex.InnerException.Message, divMessage, ltlMessage);
Chiklu.Soumya 22-Apr-13 11:27am
Thanks for reply. But couldn't understand your solution. Please read my query carefully.
Chiklu.Soumya 22-Apr-13 11:38am
My query is like creating an account in gmail or yahoo for first time where a username is suggested by a lable whether typed username is available or not.
Maksud Saifullah Pulak 22-Apr-13 11:52am
yes i understand you problem.By my solution is just resolved the message information.But you can apply your own logic to see the message.You may call function on textbox text change event or onblur.You also call web service to get the current exists data.

Chiklu.Soumya 22-Apr-13 12:01pm
I need your help. Can you get me the solution. I don't know javascript. Thanks in advance.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 22 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100