Change Onclick event dynamically for an ImageButton control

F

fabrice

Hello,

I d like to modify the Onclik Event of an ImageButton control in code
behind.
But when i do it , i get an error.

This is ma code :

The control is the pasx page :

<asp:ImageButton id="id1" Visible="false" runat="server"
EnableViewState="false" CausesValidation="false" ImageAlign="AbsMiddle" />



Déclaration in Code Behind :

...
Protected WithEvents id1 As ImageButton
...

Sub Page_Load...

If .. mon test
id1 .Visible=True
AddHandler id1.onClick, AddressOf doExcelExport
....
End Sub


The error :

Compiler Error Message: BC30390:
'System.Web.UI.WebControls.ImageButton.Protected Overridable Sub OnClick(e
As System.Web.UI.ImageClickEventArgs)' is not accessible in this context
because it is 'Protected'.


If someone can explain me the problem et show me how to do that ..

thanks a lot
fabrice.
 
C

Cowboy \(Gregory A. Beamer\)

Add to attributes:

ImageButton1.Attributes.Add("onClick", "alert('you clicked me!');");


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top