Member_2_5230414
asked on
VB.net check username is available
Hello,
I'm trying to check my mysql database to see if users are in the database in real time.
Green if username is not user - red if not.
code is
but it does nothing live??? no red or green
http://runningprofiles.com/signup.aspx
I'm trying to check my mysql database to see if users are in the database in real time.
Green if username is not user - red if not.
code is
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
UserName:
<asp:TextBox ID="txtUName" runat="server"
ontextchanged="txtUName_TextChanged"
AutoPostBack="True"/>
<asp:Image ID="imgUsr" runat="server" Visible="false"/>
<asp:Label ID="lblUsr" runat="server"/>
</ContentTemplate>
</asp:UpdatePanel>
Imports System.Data
Imports MySql.Data.MySqlClient
Partial Class signup
Inherits System.Web.UI.Page
Dim MysqlConn As MySqlConnection
Dim con As New mySqlConnection(ConfigurationManager.ConnectionStrings("dbconnection").ConnectionString)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub txtUName_TextChanged(sender As Object, e As EventArgs)
If txtUName.Text <> String.Empty Then
Dim strSelect As String = "SELECT COUNT(*) FROM members WHERE Username = txtUName.Text.Trim().ToString()"
Dim cmd As New mySqlCommand(strSelect, con)
cmd.Parameters.Add(txtUName.Text.Trim().ToString())
con.Open()
Dim result As Integer = DirectCast(cmd.ExecuteScalar(), Int32)
con.Close()
If result >= 1 Then
imgUsr.ImageUrl = "unavailable.png"
imgUsr.Visible = True
lblUsr.Text = "Username not available"
lblUsr.ForeColor = System.Drawing.Color.Red
Else
imgUsr.ImageUrl = "tick.png"
imgUsr.Visible = True
lblUsr.Text = "Available"
lblUsr.ForeColor = System.Drawing.Color.Green
End If
End If
End Sub
End Class
but it does nothing live??? no red or green
http://runningprofiles.com/signup.aspx
ASKER
Thanks Shaun - you are correct and i updated the code to reflect this but it still does not work sadly
Do you need to include the <triggers> tag as part of your UpdatePanel, as mentioned here?
http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-updatepanel-triggers
http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-updatepanel-triggers
ASKER
I tried to stick it round the textbox as that would be the trigger with no luck sadly
Have you attempted to debug the code to see if the event is firing?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
It should look something like:
Open in new window