Custom Control Click Event not firing.

I

irislogic_1

Hi

We have developed a User Control in ASP.Net, which includes a DataList. In
the ItemTemplate of DataList, we are using Custom Radio button.
The CustomRadio Button inherits RadioButton, implements IPostBackDataHandler
and has an EventHandler CustomCheckedChanged.
At Runtime, DataList is binded with DataSource. During OnItemCreated, we are
registering CustomCheckedChanged event for each CustomRadioButton Created and
making the AutoPostBack property true.

The problem we are facing is, onPostBack the CustomCheckedChanged Event is
not firing.

We have created a TestApplication, with the same setup as in our production
application. To our surprise the event is firing and it is working fine.
The framework of our TestApplication and the Production is same. The only
difference is that in the production, we are having many more UserControls.

Also we have enabled the Viewstate of the controls, still OnPostBack
__VIEWSTATE is not having any value. Can anyone help us on this.
 
L

Lachlan James

Hi,

I'm not sure why that is not working, but I might know
another (maybe better) way you could do this.

Rather than registering the event handlers for your custom
radio button inside OnItemCreated, you could bubble the
OnCheckChanged event to the parent datalist by overriding
OnCheckChanged and calling RaiseBubbleEvent inside that
method.

If you pass an instance of commandevent args then that
should will invoke the datalists command event. Then you
can reference the radiobutton list inside the ItemCommand
eventhandler of the datalist.

E.g.

// Goes insdie custom radiobuttonlist
protected override void OnCheckChanged(EventArgs e)
{
if (this.NamingContainer is DataList)
{
this.RaiseBubbleEvent(this, new CommandEventArgs
("command name", "command arg"))
}
}

// Goes inside the page.
void DataList_ItemCommand(object sender, CommandEventArgs
e)
{
if (sender as RadioButtonList != null)
{
// do stuff.
}
}

Hope this helps.

Lachlan
 
M

Mike MacMillan

Hello,
if you are not creating the dynamic objects before your control calls
LoadViewState(), the control the method points to will be null (ie, it wont
fire, it will just postback). try making sure the controls are created in
the OnInit() method of the control.

mike
 

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,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top