开发者

detect a postback from a radiobutton list

开发者 https://www.devze.com 2022-12-30 00:03 出处:网络
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

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号