473,395 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

error handles clause requires With Events Variable

HI There,

I am trying to submit a form when a selection is made from a dropdown list,
I keep getting the error "Handles clause requires With Events Variable".
Could someone help me with the syntax?
Sean - Thanks in advance
<script language="vb" runat="server">

Private Sub lstRegion_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles lstRegion.SelectedIndexChanged
response.write ("test")
End Sub

</script>

<html>
<body>
<form runat=server>

<ASP:DropDownList id=lstRegion AutoPostBack="true" name=lstRegion
maxlength= "40" SelectedIndexChanged=lstRegion_SelectedIndexChange d
runat=server>
<asp:ListItem Value="1">New South Wales</asp:ListItem>
<asp:ListItem Value="2">Victoria</asp:ListItem>
<asp:ListItem Value="3">Tasmania</asp:ListItem>
<asp:ListItem Value="4">South Australia</asp:ListItem>
<asp:ListItem Value="5">Western Australia</asp:ListItem>
<asp:ListItem Value="6">Northern Territory</asp:ListItem>
<asp:ListItem Value="7">Queensland</asp:ListItem>
</ASP:DropDownList>
</form>
</html>
</body>
Nov 18 '05 #1
3 2342
When you try to submit the ASP.NET Web Form with a dropdownlist you do it by
creating an event handler for the SelectedIndexChanged event using the
AutoPostback property. Well, for your control to expose events it has to be
declared using the WithEvents clause otherwise you won't be able to handle
any event with your code. In short, your control declaration has to look
like this:

Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList

Alan Ferrandiz
MCT,MCDBA,MCSD
MSF Practitioner
"Sean" <se**********@shopsmart.com.au> escribió en el mensaje
news:uu**************@TK2MSFTNGP12.phx.gbl...
HI There,

I am trying to submit a form when a selection is made from a dropdown list, I keep getting the error "Handles clause requires With Events Variable".
Could someone help me with the syntax?
Sean - Thanks in advance
<script language="vb" runat="server">

Private Sub lstRegion_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles lstRegion.SelectedIndexChanged
response.write ("test")
End Sub

</script>

<html>
<body>
<form runat=server>

<ASP:DropDownList id=lstRegion AutoPostBack="true" name=lstRegion
maxlength= "40" SelectedIndexChanged=lstRegion_SelectedIndexChange d
runat=server>
<asp:ListItem Value="1">New South Wales</asp:ListItem>
<asp:ListItem Value="2">Victoria</asp:ListItem>
<asp:ListItem Value="3">Tasmania</asp:ListItem>
<asp:ListItem Value="4">South Australia</asp:ListItem>
<asp:ListItem Value="5">Western Australia</asp:ListItem>
<asp:ListItem Value="6">Northern Territory</asp:ListItem>
<asp:ListItem Value="7">Queensland</asp:ListItem>
</ASP:DropDownList>
</form>
</html>
</body>

Nov 18 '05 #2
Hi Alan,

I have made a declaration at the top of the page to use the namespace, in
regards to where I put the declaration that you posted I have tried to place
it all over the page but I still receive an error, could you help me out
with the syntax?

Seam

<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<% @Import Namespace="System.Web.UI.WebControls.DropDownList" %>

<script language="vb" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)

' BindData()

End Sub
Private Sub lstRegion_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles lstRegion.SelectedIndexChanged
Protected WithEvents DropDownList1 As
System.Web.UI.WebControls.DropDownList
response.write ("test")
End Sub
</script>

<html>
<body>
<form runat=server>

<ASP:DropDownList id=lstRegion AutoPostBack="true" name=lstRegion
maxlength= "40" SelectedIndexChanged=lstRegion_SelectedIndexChange d
runat=server>
<asp:ListItem Value="1">New South Wales</asp:ListItem>
<asp:ListItem Value="2">Victoria</asp:ListItem>
<asp:ListItem Value="3">Tasmania</asp:ListItem>
<asp:ListItem Value="4">South Australia</asp:ListItem>
<asp:ListItem Value="5">Western Australia</asp:ListItem>
<asp:ListItem Value="6">Northern Territory</asp:ListItem>
<asp:ListItem Value="7">Queensland</asp:ListItem>
</ASP:DropDownList>
</form>
</html>
</body>


"Alan Ferrandiz Langley" <af********@online.labroe.com> wrote in message
news:uZ*************@TK2MSFTNGP11.phx.gbl...
When you try to submit the ASP.NET Web Form with a dropdownlist you do it by creating an event handler for the SelectedIndexChanged event using the
AutoPostback property. Well, for your control to expose events it has to be declared using the WithEvents clause otherwise you won't be able to handle
any event with your code. In short, your control declaration has to look
like this:

Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Alan Ferrandiz
MCT,MCDBA,MCSD
MSF Practitioner
"Sean" <se**********@shopsmart.com.au> escribió en el mensaje
news:uu**************@TK2MSFTNGP12.phx.gbl...
HI There,

I am trying to submit a form when a selection is made from a dropdown

list,
I keep getting the error "Handles clause requires With Events Variable".
Could someone help me with the syntax?
Sean - Thanks in advance
<script language="vb" runat="server">

Private Sub lstRegion_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstRegion.SelectedIndexChanged
response.write ("test")
End Sub

</script>

<html>
<body>
<form runat=server>

<ASP:DropDownList id=lstRegion AutoPostBack="true" name=lstRegion
maxlength= "40" SelectedIndexChanged=lstRegion_SelectedIndexChange d
runat=server>
<asp:ListItem Value="1">New South Wales</asp:ListItem>
<asp:ListItem Value="2">Victoria</asp:ListItem>
<asp:ListItem Value="3">Tasmania</asp:ListItem>
<asp:ListItem Value="4">South Australia</asp:ListItem>
<asp:ListItem Value="5">Western Australia</asp:ListItem>
<asp:ListItem Value="6">Northern Territory</asp:ListItem>
<asp:ListItem Value="7">Queensland</asp:ListItem>
</ASP:DropDownList>
</form>
</html>
</body>


Nov 18 '05 #3
Well apparently you were missing the quotes when mapping the OnSelectedIndexChanged event to a lstRegion_SelectedIndexChanged event handler, I made that change to the code below and it runs ok. Plus you don't need to declare a variable for your control since you are working inline code, declaring a <% @Import Namespace="System.Web.UI.WebControls.DropDownList" %> statement is not correct since it is not a namespace but a class.
Hope this helps

Alan Ferrandiz Langley
MCT, MCDBA, MCSD
MSF Practitioner

<HTML>
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<script language="vb" runat="server">

Sub Page_Load(sender as Object, e as EventArgs)
If Not IsPostBack Then
Response.Write ("Page_Load")
End If
End Sub

Sub lstRegion_SelectedIndexChanged(sender as Object, e as EventArgs)
Response.Write (lstRegion.SelectedItem.Text)
End Sub

</script>
<body>
<form runat="server" ID="Form1">
<asp:DropDownList id="lstRegion" AutoPostBack="true" maxlength="40" runat="server" OnSelectedIndexChanged="lstRegion_SelectedIndexCha nged">
<asp:ListItem Value="1">New South Wales</asp:ListItem>
<asp:ListItem Value="2">Victoria</asp:ListItem>
<asp:ListItem Value="3">Tasmania</asp:ListItem>
<asp:ListItem Value="4">South Australia</asp:ListItem>
<asp:ListItem Value="5">Western Australia</asp:ListItem>
<asp:ListItem Value="6">Northern Territory</asp:ListItem>
<asp:ListItem Value="7">Queensland</asp:ListItem>
</asp:DropDownList>
</form>
</body>
</HTML>

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Roby2222 | last post by:
Is there any advantage to using the Handles clause vs. using the AddHandler to map events?
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
2
by: Moe Sizlak | last post by:
Hi, I am trying to create an custom event to fill an image control, I keep getting the error "Handles clause requires a WithEvents variable." What am I missing? Moe Private Sub...
0
by: HKSHK | last post by:
This list compares the error codes used in VB.NET 2003 with those used in VB6. Error Codes: ============ 3: This Error number is obsolete and no longer used. (Formerly: Return without GoSub)...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Languageâ€, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
0
by: mchuc7719 | last post by:
Hello, I have a Vb.Net 2005 ClassLibrary, when I try to compile using MSBee, only get errors. Before I to run the command line, I open in notepad the .vbproj and I was add the next line: ...
4
by: Dennis | last post by:
I have a page in ASP.NET 2.0. I add a button in design view and the page runs fine. I then double-click the button to create the click method in the code. Then when I run the page I get the...
11
by: Jim in Arizona | last post by:
I've looked around the web but can't find anything to help me out. I was able to get some code to move some files from one directory to another, which works fine: ...
0
by: Mark C. Stock | last post by:
"Mark C. Stock" <mcstockX@Xenquery .comwrote in message news:... | | "Berend" <Berend.Brinkhuis@evatone.comwrote in message | news:bdd9ac20.0401271301.22cdb65e@posting.google.com... | | I am...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.