Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Newbie question (asp controls and events)

Reply
Thread Tools

Newbie question (asp controls and events)

 
 
Grey Alien
Guest
Posts: n/a
 
      07-09-2007
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 ?



 
Reply With Quote
 
 
 
 
Dariusz Tomon
Guest
Posts: n/a
 
      07-09-2007
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" <(E-Mail Removed)> napisal w wiadomosci
news:(E-Mail Removed)...
>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 ?
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controls.Count, Controls.IsSynchronized, and Controls.SyncRoot Nathan Sokalski ASP .Net 4 09-05-2007 03:27 AM
Newbie question - User Controls and Events Mr Not So Know It All ASP .Net 1 01-15-2007 08:54 PM
newbie: HTML controls vs Web controls R.A.M. ASP .Net 2 11-16-2006 08:21 AM
NEWBIE - Server Controls in User Controls Dave ASP .Net 0 11-29-2004 08:06 PM
dumb newbie question (or newbie dumb question) Jerry C. Perl Misc 8 11-23-2003 04:11 AM



Advertisments