tags:

views:

43

answers:

2

I am trying to detect a postback from Radiobutton list. I am trying to use following code:

If Page.Request.Params.Get("__EVENTTARGET") = optDownload.UniqueID.ToString Then

But Page.Request.Params.Get("__EVENTTARGET") returns

"ctl00$ContentPlaceHolder1$pnlBarAccounts$i0$i2$i0$CHChecking$Acct1$optDownload$4"

And optDownload.UniqueID.ToString returns

"ctl00$ContentPlaceHolder1$pnlBarAccounts$i0$i2$i0$CHChecking$Acct1$optDownload"

There is a difference in last 2 characters, how do I detect a postback from Radiobutton list?

A: 

Doesn't the RadioButtonList have an event you could listen to?

Matti Virkkunen
+1  A: 

The $4, I'm assuming, relates to the index of the selection radio options.

Just use the string contains function, i.e.

if (Page.Request.Params.Get("__EVENTTARGET").Contains(optDownload.UniqueID.ToString))
{
   // Radio list caused the postback
}

Anyway, that's very bad. You should be listening for the event on the RadioButtonList. Hook into the SelectedIndexChange event.

RadioButtonList list = new RadioButtonList();
list.SelectedIndexChanged += new EventHandler(list_SelectedIndexChanged);

protected void list_SelectedIndexChanged(object sender, EventArgs e)
{
   // Your radio button fired the postback
}

That'll work, but it sounds like you're fixing the wrong problem for whatever reason you need to know if the list caused a postback.

GenericTypeTea
I know I have been doing all the logic in SelectedIndex changed but this radiobutton list is on a user control this user control is created user on another user control and that user control is created dynamically on Telerik RadPanel bar with dynamically creaing panelitems and multiple user controls with Ajaxification. That's why I was trying to fiugre out what's going wrong. Anyways thanks for your answer. When I click on option button before it fires selected index changed page load was fired.