transmitting eventHandler pb

F

Franck

Hello,
I wrote my proper web control using a button and a few other components
in order to allow the page iclunding the control to capture the click
event from the button

i did that

//class declaration
public class ButtonDreamWeaver : Control, INamingContainer

public event EventHandler PicClicked;
// button creation
protected override void CreateChildControls()
{
// the button
imgBtnState= new ImageButton();
imgBtnState.ImageUrl=imgStatic;
imgBtnState.Click+=new ImageClickEventHandler(imgBtnState_Click);
// adding the button to this control
this.Controls.Add(imgBtnState);
}

// capturing the event
protected override void CreateChildControls()
{
[............]
imgBtnState.Click
+=new ImageClickEventHandler(imgBtnState_Click);
}

//resending the event PicClicked
private void imgBtnState_Click(object sender, ImageClickEventArgs e)
{
PicClicked(this,e);
}

But if i don't register the event on the page,
I recieve a null reference exception so it forces my control to have its
event registered

Where am I wrong?

Thank you
 
G

Guest

G'day Franck.

Try this:

private void imgBtnState_Click(object sender, ImageClickEventArgs e)
{
if ( PicClicked!= null )
{
PicClicked(this,e);
}
}

Hth!

Cheers,

Paul
 
F

Franck

works perfectly!
thanks a lot :)
G'day Franck.

Try this:

private void imgBtnState_Click(object sender, ImageClickEventArgs e)
{
if ( PicClicked!= null )
{
PicClicked(this,e);
}
}

Hth!

Cheers,

Paul

:

Hello,
I wrote my proper web control using a button and a few other components
in order to allow the page iclunding the control to capture the click
event from the button

i did that

//class declaration
public class ButtonDreamWeaver : Control, INamingContainer

public event EventHandler PicClicked;
// button creation
protected override void CreateChildControls()
{
// the button
imgBtnState= new ImageButton();
imgBtnState.ImageUrl=imgStatic;
imgBtnState.Click+=new ImageClickEventHandler(imgBtnState_Click);
// adding the button to this control
this.Controls.Add(imgBtnState);
}

// capturing the event
protected override void CreateChildControls()
{
[............]
imgBtnState.Click
+=new ImageClickEventHandler(imgBtnState_Click);
}

//resending the event PicClicked
private void imgBtnState_Click(object sender, ImageClickEventArgs e)
{
PicClicked(this,e);
}

But if i don't register the event on the page,
I recieve a null reference exception so it forces my control to have its
event registered

Where am I wrong?

Thank you
 
G

Guest

No worries, glad it helped...

P

Franck said:
works perfectly!
thanks a lot :)
G'day Franck.

Try this:

private void imgBtnState_Click(object sender, ImageClickEventArgs e)
{
if ( PicClicked!= null )
{
PicClicked(this,e);
}
}

Hth!

Cheers,

Paul

:

Hello,
I wrote my proper web control using a button and a few other components
in order to allow the page iclunding the control to capture the click
event from the button

i did that

//class declaration
public class ButtonDreamWeaver : Control, INamingContainer

public event EventHandler PicClicked;
// button creation
protected override void CreateChildControls()
{
// the button
imgBtnState= new ImageButton();
imgBtnState.ImageUrl=imgStatic;
imgBtnState.Click+=new ImageClickEventHandler(imgBtnState_Click);
// adding the button to this control
this.Controls.Add(imgBtnState);
}

// capturing the event
protected override void CreateChildControls()
{
[............]
imgBtnState.Click
+=new ImageClickEventHandler(imgBtnState_Click);
}

//resending the event PicClicked
private void imgBtnState_Click(object sender, ImageClickEventArgs e)
{
PicClicked(this,e);
}

But if i don't register the event on the page,
I recieve a null reference exception so it forces my control to have its
event registered

Where am I wrong?

Thank you
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top