Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Newbie question (asp controls and events) (http://www.velocityreviews.com/forums/t520714-newbie-question-asp-controls-and-events.html)

Grey Alien 07-09-2007 10:31 PM

Newbie question (asp controls and events)
 
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 ?




Dariusz Tomon 07-09-2007 10:52 PM

Re: Newbie question (asp controls and events)
 
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

Uzytkownik "Grey Alien" <grey@andromeda.com> napisal w wiadomosci
news:wLidnW7r_NsgKg_bRVnyiAA@bt.com...
>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 ?
>
>
>





All times are GMT. The time now is 08:10 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.