2

I have the following RadioButtons:

<asp:RadioButton id="rdoStandard" runat="server" Checked="true" GroupName="delivery" OnCheckedChanged="Check_Clicked" />

<asp:RadioButton ID="rdoExpress" runat="server" GroupName="delivery" OnCheckedChanged="Check_Clicked" />

<asp:RadioButton ID="rdoNextDay" runat="server" GroupName="delivery" OnCheckedChanged="Check_Clicked" />

And in the code behind I have this:

 Protected Sub Check_Clicked(ByVal sender As Object, ByVal e As EventArgs) Handles rdoStandard.CheckedChanged, rdoExpress.CheckedChanged, rdoNextDay.CheckedChanged
            RaiseEvent DeliveryOptionChanged()
        End Sub

I have tried the above but also tried different ways, such as a click method for each of the RadioButtons and I never hit the Check_Clicked method.

I do not want to AutoPostBack, and cannot see why you would want to if you were firing an event?

Its been a while since I used VB and WebForms, Can someone help me with this?

DevDave
  • 6,700
  • 12
  • 65
  • 99

1 Answers1

5

You need to set AutoPostBack to true if you want to trigger the event immediately, default is false.

<asp:RadioButton id="rdoStandard" AutoPostback="true" runat="server" Checked="true" GroupName="delivery" OnCheckedChanged="Check_Clicked" />

Note that a RadioButton inherits from CheckBox, therefor it inherits the AutoPostback property therefrom

Edit: If you want to avoid a postback, this event is also raised on the next roundtrip to the server when you don't set AutoPostback to true. You could for example use a submit-button, both, the Button's and also the CheckBox' click events are raised successive.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • does the AutoPostback cause the whole page to refresh? – DevDave May 02 '12 at 09:56
  • @Tyler: If you don't use ASP.NET-Ajax, yes, as every postback. Edited my answer. – Tim Schmelter May 02 '12 at 09:57
  • So would it be possible to fire the event and prevent the postback with ASP.NET-Ajax? And could you show me how? – DevDave May 02 '12 at 10:00
  • @Tyler: Even ASP.NET Ajax does not prevent from postback, actually it also passes the whole page-lifecycle. The only difference is that not the whole page is refreshed on the client but only parts of it(defined via UpdatePanels). So you won't see any flickering. Apart from that i would suggest to read some Ajax tutorials like this: http://ajax.net-tutorials.com/controls/updatepanel-control/ – Tim Schmelter May 02 '12 at 10:17
  • yeh its been a while since i did all that stuff, but guess i'm going to have to go down that road. thanks – DevDave May 02 '12 at 10:19