'Click' is not an event of 'System.Web.UI.WebControls.Image'

Hi,

I have an imagebutton named pbx in asp page.

My Codes:

AddHandler pbx.Click, AddressOf Me.pbx_onClick

Public Sub pbx_onClick(ByVal sender As Object, ByVal e As Web.UI.ImageClickEventArgs)

        a few code line.........

End Sub

when i try to publish to site ,i get an error : 'Click' is not an event of 'System.Web.UI.WebControls.Image'

How can I solve this problem?

0
maroonty
1/10/2008 3:50:59 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

11 Replies
637 Views

Similar Articles

[PageSpeed] 26

I'm not a VB guy, but try adding "Handles pbx.Click" to the end of your second line

Public Sub pbx_onClick(ByVal sender As Object, ByVal e As Web.UI.ImageClickEventArgs) Handles pbx.Click

 

0
barryman9000
1/10/2008 4:40:25 PM

Looking at the text in your error...

Are you absolutely *sure*  that pbx is an imagebutton, and not simply an image?

If pbx were an imagebutton control then it would be of class System.Web.UI.WebControls.ImageButton

please post your /aspx file to let us see more..

I would also recommend using the "Handles" attribute too...

(just noticed you're declaring this a "public" - Maybe that's why you need to assign the handler programmatically?


Kelsey Thornton
(In the Netherlands)

Don't forget - Mark the post which answered your question with "Answer", then that user will get some kudos, and your post will be marked as "Answered" for future readers!

(VB code examples preferred)
0
KelseyThornton
1/10/2008 5:11:26 PM

KelseyThornton:
I would also recommend using the "Handles" attribute too...

No Kelsey, "Public Sub pbx_onClick(ByVal sender As Object, ByVal e As Web.UI.ImageClickEventArgs) Handles pbx.Click" will wire the pbx's OnClick event twice, and cause what's in that pbx_onClick be excuted twice, when the pbx is clicked.

The thread OP's syntax is just right.

KelseyThornton:

Are you absolutely *sure*  that pbx is an imagebutton, and not simply an image?

If pbx were an imagebutton control then it would be of class System.Web.UI.WebControls.ImageButton

However, I agree with this.

Regards,

Ivan.

0
Ivan
1/14/2008 6:55:01 AM

Ivan Xin - MSFT:

KelseyThornton:
I would also recommend using the "Handles" attribute too...

No Kelsey, "Public Sub pbx_onClick(ByVal sender As Object, ByVal e As Web.UI.ImageClickEventArgs) Handles pbx.Click" will wire the pbx's OnClick event twice, and cause what's in that pbx_onClick be excuted twice, when the pbx is clicked.

The thread OP's syntax is just right.

That's why I put

KelseyThornton:

just noticed you're declaring this a "public" - Maybe that's why you need to assign the handler programmatically?

But does declaring the sub "handles..." without also doing the "Addhandler" wire up the event twice?
Or are these two effectively the same thing, and doing both will wire it up twice?
Is it possible to use "Handles" with "Public"?

 


Kelsey Thornton
(In the Netherlands)

Don't forget - Mark the post which answered your question with "Answer", then that user will get some kudos, and your post will be marked as "Answered" for future readers!

(VB code examples preferred)
0
KelseyThornton
1/14/2008 7:18:44 AM

KelseyThornton:
Or are these two effectively the same thing, and doing both will wire it up twice?

That is correct. public Sub OnpbxClick(...) Handles pbx.Click is equal to "addhandler pbx.Click, addressof OnpbxClick" .

Whether the method is public or not is not a relevant issue here. The key word public or protected is not part of the function signature.

Regards,

Ivan.

0
Ivan
1/14/2008 7:54:47 AM

I am absolutely sure that pbx is an imagebutton.

0
maroonty
1/14/2008 11:07:21 AM

maroonty:

I am absolutely sure that pbx is an imagebutton.

Can you post your .aspx to show this?

The error you say you are getting says that it is simply an image control.

 


Kelsey Thornton
(In the Netherlands)

Don't forget - Mark the post which answered your question with "Answer", then that user will get some kudos, and your post will be marked as "Answered" for future readers!

(VB code examples preferred)
0
KelseyThornton
1/14/2008 6:48:56 PM

<asp:tableCell ID="tableCell6" runat="server" Height="22px" Width="20px">

<asp:Imagebutton ID="pbx" runat="server" Height="17px" ImageUrl="medya/pbx1.jpg" ToolTip="Pbx"

Width="17px" />

</asp:tableCell>

 That s aspx codes.

0
maroonty
1/15/2008 10:54:22 AM

I used the aspx code you supplied and put it in a simple form on a default page.

I used the " handles"  methos rather than the AddHandler, and it all works fine.

Is this control buried some layers down in a data grid or some such? Maybe in a template field?

My noddy page is as follows:

 

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Public Sub pbx_onClick(ByVal sender As Object, ByVal e As Web.UI.ImageClickEventArgs) Handles pbx.Click

        Lbl1.Text = "you clicked it"

    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Table ID="Table1" runat="server" Width="100%">
            <asp:TableRow>
                <asp:TableCell ID="tableCell6" runat="server">
                    <asp:ImageButton ID="pbx" runat="server" Height="17px" ImageUrl="medya/pbx1.jpg"
                        ToolTip="Pbx" Width="17px" />
                    <asp:Label ID="Lbl1" runat="server" Text="Label"></asp:Label>
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>
    </div>
    </form>
</body>
</html>
 
Kelsey Thornton
(In the Netherlands)

Don't forget - Mark the post which answered your question with "Answer", then that user will get some kudos, and your post will be marked as "Answered" for future readers!

(VB code examples preferred)
0
KelseyThornton
1/15/2008 5:09:59 PM

This page also works if you replace the script block with the following:

 

<script runat="server">


    Public Sub pbx_onClick(ByVal sender As Object, ByVal e As Web.UI.ImageClickEventArgs)

        Lbl1.Text = "you clicked it"

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        AddHandler pbx.Click, AddressOf pbx_onClick

    End Sub
</script>

What are you not telling us?


Kelsey Thornton
(In the Netherlands)

Don't forget - Mark the post which answered your question with "Answer", then that user will get some kudos, and your post will be marked as "Answered" for future readers!

(VB code examples preferred)
0
KelseyThornton
1/15/2008 5:17:08 PM

Addhandler method is working in my page too but the problem is that when i tried to publish website ,it gives an error so that  "Error 7 'Click' is not an event of 'System.Web.UI.WebControls.Image'."

0
maroonty
1/16/2008 7:03:58 AM
Reply:

Similar Artilces:

'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image'
In my aspx page, I have the following snippet: <%@ Page Language="C#" %><%@ Import Namespace="System.IO" %><%@ Import Namespace="System.Drawing" %>     public System.Drawing.Image Test()    {      ...    }  I keep getting the 'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image' error in my Test function (which returns an Image). How do I fix this? Right which is possible; use the full...

CS0104: 'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image'
 CS0104: 'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image'   <%@ Page Language="C#" %> <%@ Import Namespace="System.Drawing" %> <%@Import Namespace="System.Drawing.Imaging" %>   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script type="text/C#" runat="server"> void Page_Load() {//The @ means "Ignore escape characters!" in the following string. It is a verbatim //literal string - any backslashes (and newlines) in...

Converting 'System.Drawing.Image' to 'System.Web.UI.WebControls.Image'
Hello,I have an image stored on disk, that I am manipulating using the Drawing classes, and creating a 300x400 thumbnail from. Then, I want to display this image in an Image control on my webpage. How do I do that?Code:                    //Create the delegate                    System.Drawing.Image.GetThumbnailImageAbort dummyCallBack;           &nbs...

Error Serializing Value 'System.Web.UI.WebCOntrols.TreeNode' of type 'System.Web.UI.WebCOntrols.TreeNode'
Hi, I am  getting the error stated in the subject when i am storing a TreeNode in a ViewState and then using it as follows if (ViewState["ProductCounty"]!=null) { TreeNode _productCountyNode = DataTree.FindNode(((TreeNode)ViewState["ProductCounty"]).ValuePath); _productCountyNode.Expand(); } what could be causing this error? Hi, I believe TreeNode isn't serializable in a way its required for objects which can be put to ViewState - as reference - (TreeNode implements IStateManager and is meant to work together with TreeView itself saving it...

Unable to cast object of type 'System.Web.UI.WebControls.FormView' to type 'System.Web.UI.WebControls.DropDownList'.
Hi,  I have a formview with a dropdownlist created dynamically. i want to determine whether the dropdownlist was clicked. the code is written in the FormView1_DataBound method. I get the following error in the line below that is in italics and underlined: Unable to cast object of type 'System.Web.UI.WebControls.FormView' to type 'System.Web.UI.WebControls.DropDownList'.   Here is my code: ddl_iFullname = New DropDownList ddl_iFullname.ID = "ddl_iFullname" ddl_iFullname.DataSource = ObjectDataSource3 ddl_iFullname.DataTextField = "fullname" ddl_iFullname.DataValueField = "...

Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.Web.UI.WebControls.TextBox'
I am attempting to "Update" a field in a Datagrid, but no matter what I do (Using either Label or Text Boxes)  I keep getting the same error: Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.Web.UI.WebControls.TextBox' The Error is highlighted below in the Sub... <==THE FIELD THAT CALLS THE ERROR  Any help would be greatly appreciated !!! Thanks !!   The code is as follows... <table border=0 height=210 bordercolor=olive ><tr valign=top><td> <asp:datagrid id="FacilityDataGrid"...

Error: Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField'
Hello, I am getting the following error during compiliation. Any suggestions to fix it. Thanks. Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField' protected void gvEvents_RowCommand(Object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Select") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvEvents.Rows[index]; string sID; ButtonField btn; if (selectedRow.RowType == DataControlRowType.DataRow) { sID = ((ButtonField)selectedRow.FindControl("ID")).DataTextFi...

Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.TextBox'
Hello, Goal: enter a number in two fields HoursPerUnit and PeoplePerUnit and the value for the third field, TotalHoursPerUnit will populate after the the number in the two fields have been caculated.  Using the code below I receive the error message above.  Please tell me what am I doing wrong? Do I need to cast the text as a literal?  Please help? Thank you in advance, <%@ Page Language="VB" MasterPageFile="Default.master" AutoEventWireup="false" CodeFile="frmHR.aspx.vb" Inherits="frmHR"...

Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.TextBox'.
Hi, any idea why I'm getting the following error?Line 45: protected void CartGrid_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e) Line 46: { Line 47: TextBox QuantityTextBox = (TextBox)CartGrid.Rows[e.RowIndex].Cells[2].Controls[0]; Line 48: int Quantity = Convert.ToInt32(QuantityTextBox.Text); Line 49: Are you sure that the control at CartGrid.Rows[e.RowIndex].Cells[2].Controls[0] isn't a LiteralControl?  How are you creating code this in your code?Brent JenkinsASP.NET, C#, Web Developerwww.valewebdesign.co.uk  ...

'DataBinding' is not an event of 'System.Web.UI.WebControls.ListItem'
Help I got some problem here I have successfully bind some date from database to a datalist I want to allow user to edit the data with a click of the edit button, which I have already done that. Once the edit button has been clicked, it shoud then get the value from database and display it on the form. I can only get the value and display on the textbox, and when it comes to asp:RaddioButtonList as below <asp:RadioButtonList id="gender" runat="server" RepeatDirection="Horizontal"> <asp:ListItem Value="...

Error 1 The type 'System.Web.UI.WebControls.LinqDataSource' exists in both 'c:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\3.5.0.0__31bf3856ad364e35\System.Web.Extensions.dll' and 'c:\WINDOWS\asse
Once I build project. I encounter this error. Does someone experience this error?Error    1    The type 'System.Web.UI.WebControls.LinqDataSource' exists in both 'c:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\3.5.0.0__31bf3856ad364e35\System.Web.Extensions.dll' and 'c:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\3.6.0.0__31bf3856ad364e35\System.Web.Extensions.dll'    D:\Source Code\Linq_Lesson5\Default.aspx    1    1    D:\Source Code\Linq_Lesson5\  It appears tha...

ASPNET2 HELP! CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.FileUpload'.
Server Error in '/start-movieposters' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.FileUpload'. An explicit conversion exists (are you missing a cast?) Source Error: ...

Operator '&' is not defined for types 'String' and 'System.Web.UI.WebControls.TextBox'
Can anyone tell me what this error message means, and what to do to correct it.  Here is the code that has the error:  Dim sql As Stringsql = "INSERT INTO tblConnecting (Date, Member, Name, Company, Phone, Fax, Address, NamesofAttendees, PaymentType, Email) " _ & "Values('" & Today() & "', '" & blnMember & "', '" & Me.txtName.Text & "', '" & Me.txtCompany.Text & "', '" _& Me.txtPhone.Text & "', '" & Me.txtFax.Text &...

'System.Web.UI.WebControls.DataListItem.DataItem' is a 'property' but is used like a 'method'
 HI I have a datalist with OnItemDataBoundI get the following error when I try to get the DataItem 'System.Web.UI.WebControls.DataListItem.DataItem' is a 'property' but is used like a 'method' , any idea what's wrong with the line ?  public void Item_Bound(object sender, DataListItemEventArgs e)    {        Label originalPriceLabel;        if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType == ListItemType.AlternatingItem)        {    &n...

Web resources about - 'Click' is not an event of 'System.Web.UI.WebControls.Image' - asp.net.web-forms

Resources last updated: 1/7/2016 8:47:09 AM