Newbie question (asp controls and events)

G

Grey Alien

I have manually added two radio button controls to my Asp.Net webpage
(*.aspx file - souce view). This is the code I added:

(I have not included the <%@PAGE directive and <div></div> for brevity sake)

<asp:RadioButton
ID ="rbtn1"
GroupName = "grp1"
OnCheckedChanged = "RadioButton_CheckedChanged"
Text = "Option 1"
runat="server" />

<asp:RadioButton
ID ="rbtn2"
GroupName = "grp1"
OnCheckedChanged = "RadioButton_CheckedChanged"
text="Option 2"
runat="server" />



What I find suprising is that although I have AutoEventWireup="true" in
my %@PAGE directive, I find that I still have to hand write the event
handlers for the asp controls that I add (why?)

Secondly, I succesfully manually added a Button1_Click event handler for
a button control that I added, and that compiled successfully. However,
when I added the ff event handler for the RadioButton:

protected void RadioButton_CheckChanged(Object sender, EventArgs e)
{
RadioButton rbtn = (RadioButton)sender;
if (String.Compare(rbtn.ID, "Option 1") == 0 )
TextBox1.Text = "Option 1";
else
TextBox1.Text = "Option 2";
}


I got the ff error when compiling :

Error 1 'ASP.default_aspx' does not contain a definition for
'RadioButton_CheckedChanged' C:\projects\websites\testsite\Default.aspx 37

can anyone spot what I may be doing wrong ?
 
D

Dariusz Tomon

First of all, you have to be in design view, than double click on the
RadioButton control. You will be moved to codebehind and creator will create
ready-to-use event method.

In my case when I double click RadioButton I get following entry:

protected void RadioButton1_CheckedChanged(object sender, EventArgs e)

{

}

If it does not work in your case I suppose you have an issue with your VS
environment.



Darek
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top