|
-
Nov 15th, 2004, 07:00 AM
#1
Thread Starter
New Member
WithEvents variable error message
When I try to run the following:
Private Sub ChangeBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChangeBtn.Click
Dim succ As Boolean = False
If (Page.IsValid) Then
Dim rs As Integer = UpdatePass(username.Text, userpass.Text)
If (rs > 0) Then
succ = True
End If
End If
If (succ) Then
frmchangepass.Visible = False
lblUserMessage.Text = "Your password has been changed to ..."
Else
lblUserMessage.Text = "Could not change password, please contact administrator"
End If
End Sub
I get an error message that highlights the first line of the sub and says:
"Handles clause requires a WithEvents variable."
I have to put the following code on the page and I don''t know exactly how or where:
Protected WithEvents frmchangepass As System.Web.UI.HtmlControls.HtmlForm
Thanks for any ideas.
Last edited by jarow; Nov 15th, 2004 at 07:35 AM.
-
Nov 15th, 2004, 07:30 AM
#2
Declare the ChangeBtn object WithEvents in the designer code.
Something like:
VB Code:
Protected WithEvents ChangeBtn As System.Web.UI.WebControls.Button
-
Nov 15th, 2004, 07:44 AM
#3
Thread Starter
New Member
Thanks alot...I placed the code above the following line
Private Sub ChangeBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChangeBtn.Click
and I get this error message
'ChangeBtn' is already declared as 'Protected Dim ChangeBtn As System.Web.UI.WebControls.Button' in this class.
Here is the code for the entire page. If you could tell me what I am doing wrong I would greatly appreciate it.
Sorry, I am very new to this and don't know what is entirely relevant or not. I am including all the code for the page to give you a better idea. My question is, where and how do I exactly place:
Protected WithEvents ChangeBtn As Sysem.Web.UI.WebControls.Button
Thanks very much for your help.
Here is the page:
<%@ Page Language="VB" %>
<%@ Register TagPrefix="uc0" TagName="fauna_header" Src="../controls/fauna_header.ascx" %>
<%@ Register TagPrefix="uc0" TagName="fauna_footer" Src="../controls/fauna_footer.ascx" %>
<script runat="server">
Private Sub ChangeBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChangeBtn.Click
Dim succ As Boolean = False
If (Page.IsValid) Then
Dim rs As Integer = UpdatePass(username.Text, userpass.Text)
If (rs > 0) Then
succ = True
End If
End If
If (succ) Then
frmchangepass.Visible = False
lblUserMessage.Text = "Your password has been changed to ..."
Else
lblUserMessage.Text = "Could not change password, please contact administrator"
End If
End Sub
Function UpdatePass(ByVal username As String, ByVal userpass As String) As Integer
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Inetpub\wwwr"& _
"oot\FAIBLogin\autores.mdb"
Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
Dim queryString As String = "UPDATE [authors] SET [userpass]=@newpass WHERE (([authors].[username] = @usern"& _
"ame) AND ([authors].[userpass] = @userpass))"
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_username As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
dbParam_username.ParameterName = "@username"
dbParam_username.Value = username
dbParam_username.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_username)
Dim dbParam_userpass As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
dbParam_userpass.ParameterName = "@userpass"
dbParam_userpass.Value = userpass
dbParam_userpass.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_userpass)
Dim rowsAffected As Integer = 0
dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Finally
dbConnection.Close
End Try
Return rowsAffected
End Function
</script>
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<link href="../database.css" type="text/css" rel="stylesheet" />
<style type="text/css">
<!--
.style1 {font-size: 10px}
-->
</style>
</head>
<body>
<table cellspacing="0" cellpadding="0" width="760" align="center" border="0">
<tbody>
<tr>
<td colspan="2">
<uc0:fauna_header id="UserControl1" runat="server"></uc0:fauna_header>
</td>
</tr>
<tr>
<td width="181" bgcolor="#92A8D2">
</td>
<td width="579" bgcolor="#FFFFFF">
<form id="frmchangepass" runat="server">
<table>
<tbody>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td width="130">
Username</td>
<td width="145">
<asp:TextBox id="username" runat="server"></asp:TextBox>
</td>
<td width="100"><asp:RequiredFieldValidator id="Requiredfieldvalidator1" runat="server" ControlToValidate="UserName" Display="Static" ErrorMessage="*"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Password</td>
<td>
<asp:TextBox id="userpass" runat="server"></asp:TextBox>
</td>
<td><asp:RequiredFieldValidator id="Requiredfieldvalidator2" runat="server" ControlToValidate="UserPass" Display="Static" ErrorMessage="*"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
New Password</td>
<td>
<asp:TextBox id="newpass" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
Confirm Password</td>
<td>
<asp:TextBox id="confirmpass" runat="server"></asp:TextBox>
</td>
<td><span class="style1">
<asp:CompareValidator id="CompareValidator2" runat="server" ControlToValidate="confirmpass" Display="Dynamic" ErrorMessage="Passwords do not match. Try again." ControlToCompare="newpass"></asp:CompareValidator>
</span> </td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button id="ChangeBtn" runat="server" Text="Change Password"></asp:Button>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</form>
<asp:Label id="lblUserMessage" runat="server"></asp:Label></td>
</tr>
<tr>
<td colspan="2">
<uc0:fauna_footer id="UserControl2" runat="server"></uc0:fauna_footer>
</td>
</tr>
</tbody>
</table>
</body>
</html>
Last edited by jarow; Nov 15th, 2004 at 11:00 AM.
-
Nov 16th, 2004, 01:06 AM
#4
Where is the original declaration located?
Protected Dim ChangeBtn As System.Web.UI.WebControls.Button
Just go there and modify it. Doesn't the page have a .VB file codebehind?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|