Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 141
  • Last Modified:

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
0
runnerjp2005
Asked:
runnerjp2005
  • 7
  • 6
1 Solution
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now