Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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)
    {
        try
        {
            SqlCn.Open();
            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.";
            }
            else
            {
                Label1.Text = "This username is available";
            }
        }
        catch (Exception ex)
        {
            string msg = ex.Message;
        }
Posted 22-Apr-13 6:01am

1 solution

Rate this: bad
good
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>
   </div>
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;
       }</pre>
try
               {
                   UISettings.ShowMessage("alert alert-success", "Insert Successfully", divMessage, ltlMessage);
               }
               catch (Exception ex)
               {
                   ShowMessage("alert alert-error", ex.InnerException.Message, divMessage, ltlMessage);
               }
  Permalink  
Comments
Chiklu.Soumya at 22-Apr-13 11:27am
   
Thanks for reply. But couldn't understand your solution. Please read my query carefully.
Chiklu.Soumya at 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 at 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.
 
Thanks,
Chiklu.Soumya at 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
0 OriginalGriff 325
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 Sergey Alexandrovich Kryukov 189
0 OriginalGriff 5,455
1 DamithSL 4,422
2 Maciej Los 3,860
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,010


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 22 Apr 2013
Copyright © CodeProject, 1999-2014
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