Dave -
Thanks so much for your response! That sure looks like it should work,
but
it didn't. The lblMessage (which indicates the name is taken) did not
disappear when I put the cursor in the textbox, or even after I typed in
the
textbox and tabbed to the next textbox.
Could I trouble you to take a look at the code? I put your solution at
the
end of the sub.
Private Sub btnSubmitNewMember_Click(ByVal sender As System.Object, ByVal
e
As System.EventArgs) Handles btnSubmitNewMember.Click
'Check if User Name taken
Dim daTest as SqlDataAdapter
Dim dsLogin as New DataSet
daTest = New SqlDataAdapter("Select Count(UserID) as TheCount " _
& "from tblLogin Where " _
& "UserName = '" & txtNewUserName.Text _
& "'", cnn)
daTest.Fill(dsLogin, "TheCount")
Dim NewValue as Integer
NewValue = dsLogin.Tables("TheCount").Rows(0).Item("TheCount")
'If User Name is taken, it will return a 1; otherwise if not taken,
will
return 0 and User Name is okay
If dsLogin.Tables("TheCount").Rows(0).Item("TheCount") = 0 Then
Dim cmdLogin as SqlCommand = cnn.CreateCommand
cmdLogin.CommandType = CommandType.StoredProcedure
cmdLogin.CommandText = "spTblLoginOnly"
cmdLogin.Parameters.Add(New SqlParameter("@UserName", SqlDbType.Char,
50))
cmdLogin.Parameters("@UserName").Value = txtNewUserName.Text
cmdLogin.Parameters.Add(New SqlParameter("@Password", SqlDbType.Char,
15))
cmdLogin.Parameters("@Password").Value = txtNewPassword.Text
cmdLogin.Parameters.Add(New SqlParameter("@EmailAddress",
SqlDbType.Char, 60))
cmdLogin.Parameters("@EmailAddress").Value = txtEmail.Text
cmdLogin.Parameters.Add(New SqlParameter("@ScreenName", SqlDbType.Char,
15))
cmdLogin.Parameters("@ScreenName").Value = txtScreenName.Text
cmdLogin.Parameters.Add(New SqlParameter("@UserID", SqlDbType.Int))
cmdLogin.Parameters("@UserID").Direction = ParameterDirection.Output
cnn.Open
cmdLogin.ExecuteNonQuery()
'Get the UserName from tblLogin and put it into Session
daTest = New SqlDataAdapter("Select UserID from tblLogin Where " _
& "UserName = '" & txtNewUserName.Text _
& "' and Password = '" & txtNewPassword.Text _
& "'", cnn)
daTest.Fill(dsLogin, "tblLogin")
Session("UserID") = dsLogin.Tables("tblLogin").Rows(0).Item("UserID")
cnn.Close
Response.Redirect(HttpUtility.UrlDecode(Request.QueryString("currpage")))
Else
pnlNewMember.Visible = True
lblMessage.Text = "The User Name you entered is already in use. Please
choose a different User Name."
txtNewUserName.Attributes.Add("onfocus", "document.getElementById('" +
lblMessage.UniqueID + "').style.display =""none"";")
End If
End Sub
What am I doing wrong?
--
Sandy
Dave Fancher said:
I prefer the option of just hiding it.
Assuming that your TextBox is named userName and your Label is named
errorLabel you could use the following code to add the client side event
handler to the TextBox. I would recommend placing this code somewhere
where
it will only be executed when the label is going to be marked as visible.
[C#]
userName.Attributes.Add("onfocus", "document.getElementById('" +
errorLabel.UniqueID + "').styles.display = \"none\";");
[VB - sorry if my syntax is slightly off]
userName.Attributes.Add("onfocus", "document.getElementById('" +
errorLabel.UniqueID + "').styles.display = ""none"";");
HTH
----------------
Dave Fancher
http://www.davefancher.com
John -
Thanks for your response.
Sorry for being dense, but I know absolutely nothing about javascript -
it
is the next thing on my agenda to learn.
Can you tell me where and how I would put this in my code?
--
Sandy
:
Use CSS in a javascript onfocus event
http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onfocus.asp
labelID.style.visibility = ' hidden ';
or move the label off screen with javascript
function moveTo(x, y) {
this.element.left = x;
this.element.top = y;
}
--
Regards
John Timney
ASP.NET MVP
Microsoft Regional Director
Hello -
I have a form that when submitted checks the database and if the
username
is
already taken, a label shows indicating same.
I need to make that label NOT visible after the user clicks in the
username
textbox to change the name.
Any help will be greatly appreciated!