Saturday, March 24, 2012

newbie help urgent

whatz wrong with the below code?
I get a "Handles clause requires a WithEvents variable." error......any help is appreciated

[code]
<%@dotnet.itags.org. Page Language="VB" debug="true" trace="true"%>
<script runat="server">
Private Sub Page_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load
Button1.Attributes.Add("onclick", "javascript:alert('hello world')")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button1.Click
Response.Write("Click fired...")
End Sub
</script
<html>
<body>
<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" runat="server" Text="Button">
</asp:Button>
</form>
</body>
</html>
[/code]I just tested your code and it works fine.

The only thing I can see is in your @.page declarations...

Try changing it to this...

<%@. Page Language="vb" debug="true" trace="true" AutoEventWireup="false" Codebehind="PAGE_NAME.aspx.vb" Inherits="PROJECT_NAME.PAGE_NAME" %
Just adjust the page and project name where needed.

Zath
strange...i still get the same error...since i dont have a codebehind page, i can do without "codebehind" and "inherits" attributes.

Is a known bug on Framework version 1.1.4322? or is it just me??

regards,
vj
I don't think you need the handles when you've not got a code behind page:


<%@. Page Language="VB" debug="true" trace="true"%>
<script runat="server">
Private Sub Page_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load
Button1.Attributes.Add("onclick", "javascript:alert('hello world')")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)
Response.Write("Click fired...")
End Sub
</script
<html>
<body>
<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" runat="server" Text="Button" OnClick="Button1_Click">
</asp:Button>
</form>
</body>
</html>

Added OnClick="Button1_Click" to the Button attributes..

Button1.Attributes.Add("onclick", "javascript:alert('hello world')")

Might upset it a little though.

I think it's something like that.
Nic

Hi vj,

There is no bug here. Get rid of your Handles clauses; you don't need them with inline code. In order to wire up your Button1_Click event handler to the OnClick event of your Button1 control, add the OnClick="Button1_Click" attribute to your Button1 server control tag.

thanks guys...picked up the earlier code from here:

http://www.dotnetbips.com/displayarticle.aspx?id=8

0 comments:

Post a Comment