update panel not working

I have the below code to ty check mysql database and show if username is ok or not to use (if in db no - if not then yes.

signup.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="signup.aspx.vb" Inherits="signup" %>
 <%@ Register Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" tagPrefix="ajax" %>
<asp:ScriptManager ID="scriptmanager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="updatepnl" runat="server">
<ContentTemplate>
<table>
<tr>
<td>
Enter UserName 
</td>
<td>:</td>
<td>
<asp:TextBox ID="txtun" runat="server" AutoPostBack="true" OnTextChanged="CheckUserNameAvailability"/>
</td>
<td>
<div id="checkun" runat="server"  Visible="false">
<asp:Image ID="shwimg" runat="server" Width="17px" Height="17px"/>
<asp:Label ID="lblmsg" runat="server"></asp:Label>
</div>
</td>
</tr>
<tr>
<td>
Enter Password 
</td>
<td>:</td>
<td>
<asp:TextBox ID="txpwd" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Enter Confirm Password 
</td>
<td>:</td>
<td>
<asp:TextBox ID="txtconpwd" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Button ID="txtbtn" Text="SUBMIT" runat="server" align="center" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>

Open in new window


signup.aspx.vb

Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Data
Imports System.Web.UI
Imports System.Web.UI.WebControls
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 CheckUserNameAvailability(sender As Object, e As EventArgs)
		If Not String.IsNullOrEmpty(txtun.Text) Then
			Dim con As New mySqlConnection("Data Source=localhost;Initial Catalog=runningprofiles;User ID=8888;Password=88888")
			con.Open()
			Dim cmd As New mySqlCommand("select * from members where email=@un", con)
			cmd.Parameters.AddWithValue("@un", txtun.Text)
			Dim dr As mySqlDataReader = cmd.ExecuteReader()
			If dr.HasRows Then
				checkun.Visible = True
				shwimg.ImageUrl = "Cancel.png"
				lblmsg.Text = "UserName Already Exist..!!"
			Else
				checkun.Visible = True
				shwimg.ImageUrl = "Accepted.png"
				lblmsg.Text = "Congratulation created Successfully..!!"
			End If
		Else
			checkun.Visible = False
		End If
	End Sub






    
End Class

Open in new window


but it shows nothing when entering information.... where have a gone wrong and how can i fix it??

the site itself is here: http://runningprofiles.com/signup.aspx
runnerjp2005Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sammySeltzerCommented:
It is a button click. So, try adding HANDLES bit

Protected Sub CheckUserNameAvailability(sender As Object, e As EventArgs) handles txtbtn.click or something like that.
0
runnerjp2005Author Commented:
nah its  OnTextChanged="CheckUserNameAvailability"

<asp:TextBox ID="txtun" runat="server" AutoPostBack="true" OnTextChanged="CheckUserNameAvailability"/>
0
sammySeltzerCommented:
can you explain a bit what you are trying to accomplish?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

sammySeltzerCommented:
If you are trying to copy value of first password box to the second password box, then I would suggest using javascript.


For instance,

<asp:TextBox ID="txpwd" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Enter Confirm Password 
</td>
<td>:</td>
<td>
<asp:TextBox ID="txtconpwd" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>

Open in new window

Then on pageload() event, add this line:

txpwd .Attributes.Add("onblur","CopyValue(this)")

Open in new window


Finally, the javascript:

<script language="javascript">
function CopyValue(txt)
{
var text2=document.getElementById("<%=txtconpwd.ClientID %>");
text2.value=txt.value;
}
</script>

Open in new window


Here, value of txpwd is copied to txtconpwd.

This saves you from unnecessary postback.
0
runnerjp2005Author Commented:
im actually trying to check if text is been entered into a text box - i will then check if that text is already in the database.

but even the simplest of code does nothing

Protected Sub TextBox1_TextChanged(sender As Object, e As EventArgs)
	Label1.Text = TextBox1.Text
End Sub

Open in new window



 <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"
        ontextchanged="TextBox1_TextChanged"></asp:TextBox>
   
    <asp:Label ID="Label1" runat="server"></asp:Label>

Open in new window


so then the textbox text is changed if should do something. for now im just adding it into a lable so i can see the results
0
sammySeltzerCommented:
I don't understand what you mean.
0
runnerjp2005Author Commented:
ok so I want it so if someone types in a textbox it checks and runs code if it does , in this case changes the table to the text in the text box
0
runnerjp2005Author Commented:
0
CodeCruiserCommented:
Does it work if you remove the ontextchange and instead use

Protected Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles Textbox1.TextChanged
0
sammySeltzerCommented:
This worked for me:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>AJAX User Registration Example</title>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
  <form id="form1" runat="server">
  <asp:ScriptManager runat="server" ID="sm1" />
  <script language="javascript" type="text/javascript">
      // Hook the InitializeRequest event.
      Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitializeRequest);

      function InitializeRequest(sender, args) {
          // Change div's CSS class and text content.
          $get('UserAvailability').className = 'progress';
          $get('UserAvailability').innerHTML = 'Checking availability...';
          $get('Button1').disabled = true;
      }
  </script>
  <asp:UpdatePanel runat="server" ID="up1">
    <ContentTemplate>
      <label>Username:</label> <asp:TextBox runat="server" id="txtun" AutoPostBack="true" OnTextChanged="CheckUserNameAvailability" />
      <div runat="server" id="UserAvailability"></div><br />
    </ContentTemplate>
  </asp:UpdatePanel>
  <label>Password:</label> <asp:TextBox runat="server" ID="txtpwd" TextMode="password" /><br />
  <label>Confirm:</label> <asp:TextBox runat="server" ID="txtconpwd" TextMode="password" /><br /><br />
  <asp:UpdatePanel runat="server" ID="up2">
    <ContentTemplate>
      <asp:Button runat="server" ID="Button1" 
        Text="Sign me up!" Enabled="false" />
    </ContentTemplate>
  </asp:UpdatePanel>
  <asp:Label ID="lblmsg" runat="server"></asp:Label>
  </form>
</body>
</html>

Open in new window


Imports System.Web.Security
Imports System.Collections.Generic
Imports System.Web
Imports System.Data
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data.SqlClient

Public Partial Class Admin_Default
    Inherits System.Web.UI.Page
    Dim MysqlConn As SqlConnection
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub
    Protected Sub CheckUserNameAvailability(ByVal sender As Object, ByVal e As EventArgs)
        Dim conn As New SqlConnection("Data Source=localhost;Initial Catalog=runningprofiles;User ID=8888;Password=88888")
        Dim cmd As New SqlCommand("select * from members where email=@un", conn)
        cmd.Parameters.AddWithValue("@un", txtun.Text)
        conn.Open()
        Dim dr As SqlDataReader
        System.Threading.Thread.Sleep(3000)
        dr = cmd.ExecuteReader()
        While dr.Read()
            If Password.Text = dr("username").ToString() Then
                lblmsg.Text = "Username already exists"
            Else

                lblmsg.Text = "Username available"
            End If
        End While
    End Sub

End Class

Open in new window

0
runnerjp2005Author Commented:
Hi Sammy,

I have copied the above and does nothing : http://runningprofiles.com/signup.aspx

i had to change 2 things - im using mysql db so had to chnage to a mysql connection and also
 
If Password.Text = dr("username").ToString() 

Open in new window

to  
If txtun.Text = dr("username").ToString() 

Open in new window


Here is full page code

Imports System.Web.Security
Imports System.Collections.Generic
Imports System.Web
Imports System.Data
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports MySql.Data.MySqlClient

Partial Class signup
    Inherits System.Web.UI.Page
    Dim MysqlConn As MySqlConnection
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub
    Protected Sub CheckUserNameAvailability(ByVal sender As Object, ByVal e As EventArgs)
		Dim conn As New mySqlConnection("Data Source=localhost;Initial Catalog=runningprofiles;User ID=888;Password=888")
        Dim cmd As New mySqlCommand("select * from members where email=@un", conn)
        cmd.Parameters.AddWithValue("@un", txtun.Text)
        conn.Open()
        Dim dr As mySqlDataReader
        System.Threading.Thread.Sleep(3000)
        dr = cmd.ExecuteReader()
        While dr.Read()
            If txtun.Text = dr("username").ToString() Then
                lblmsg.Text = "Username already exists"
            Else

                lblmsg.Text = "Username available"
            End If
        End While
    End Sub

End Class

Open in new window



<%@ Page Language="VB" AutoEventWireup="false" CodeFile="signup.aspx.vb" Inherits="signup" %>
 <%@ Register Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" tagPrefix="ajax" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
    <title>Running Profiles</title>
   <link href="rp.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" />
<style>
#UserAvailability {
  padding-left: 22px;
  background-position: left;
  background-repeat: no-repeat;
}
 
.taken {
  background-image: url(http://www.anh-usa.org/wp-content/uploads/2010/02/stop.jpg);
}
 
.available {
  background-image: url(http://www.clipartbest.com/cliparts/niB/GKj/niBGKjq6T.png);
}
</style>
   
</head>
<body>
<form runat="server">
<div id="header_container">
    <div id="header">
  <div id="titlehead">
Running Profiles   <div id="loginbutton" style="float:right;"> Login </div>
  </div>
 
    </div>
</div>
<!-- <div id="top-header">-->

<!-- </div>-->
	<!-- <div id="topheader-split"> -->
	<!-- <div id="topheader-split2"> -->
	<!-- </div> -->
	<!-- </div> -->
<div id="content">
<div id="content2">

 <asp:ScriptManager runat="server" ID="sm1" />
  <script language="javascript" type="text/javascript">
      // Hook the InitializeRequest event.
      Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitializeRequest);

      function InitializeRequest(sender, args) {
          // Change div's CSS class and text content.
          $get('UserAvailability').className = 'progress';
          $get('UserAvailability').innerHTML = 'Checking availability...';
          $get('Button1').disabled = true;
      }
  </script>
  <asp:UpdatePanel runat="server" ID="up1">
    <ContentTemplate>
      <label>Username:</label> <asp:TextBox runat="server" id="txtun" AutoPostBack="true" OnTextChanged="CheckUserNameAvailability" />
      <div runat="server" id="UserAvailability"></div><br />
    </ContentTemplate>
  </asp:UpdatePanel>
  <label>Password:</label> <asp:TextBox runat="server" ID="txtpwd" TextMode="password" /><br />
  <label>Confirm:</label> <asp:TextBox runat="server" ID="txtconpwd" TextMode="password" /><br /><br />
  <asp:UpdatePanel runat="server" ID="up2">
    <ContentTemplate>
      <asp:Button runat="server" ID="Button1" 
        Text="Sign me up!" Enabled="false" />
    </ContentTemplate>
  </asp:UpdatePanel>
  <asp:Label ID="lblmsg" runat="server"></asp:Label>

  

 </div>
</div>
</div>
</form>
</body>
</html>

Open in new window


Do i have something turned off that needs turning on :S
0
sammySeltzerCommented:
Ok, try this. I just dawned on me that you are already doing the validation with your query anyway.

So assuming that that query is correct, then this should work:

Imports System.Web.Security
Imports System.Collections.Generic
Imports System.Web
Imports System.Data
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports MySql.Data.MySqlClient

Partial Class signup
    Inherits System.Web.UI.Page
    Dim MysqlConn As MySqlConnection
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub
    Protected Sub CheckUserNameAvailability(ByVal sender As Object, ByVal e As EventArgs)
		Dim conn As New mySqlConnection("Data Source=localhost;Initial Catalog=runningprofiles;User ID=888;Password=888")
        Dim cmd As New mySqlCommand("select * from members where email=@un", conn)
        cmd.Parameters.AddWithValue("@un", txtun.Text)
        conn.Open()
        Dim dr As mySqlDataReader
        System.Threading.Thread.Sleep(3000)
        dr = cmd.ExecuteReader()
         If dr.HasRows Then
                lblmsg.Text = "Username already exists"
            Else
                lblmsg.Text = "Username available"
          End If
    End Sub

End Class

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
runnerjp2005Author Commented:
0
sammySeltzerCommented:
Ok, send me ALL of your code. You can zip them or you can copy and paste them here.

My version works perfectly but let me work with your version.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.