detect a postback from a radiobutton list
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?
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.
Doesn't the RadioButtonList have an event you could listen to?
精彩评论