Newbie question (asp controls and events)

Discussion in 'ASP .Net' started by Grey Alien, Jul 9, 2007.

  1. Grey Alien

    Grey Alien Guest

    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 ?
     
    Grey Alien, Jul 9, 2007
    #1
    1. Advertising

  2. 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" <> napisal w wiadomosci
    news:...
    >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, Jul 9, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. newbye
    Replies:
    0
    Views:
    592
    newbye
    Jul 6, 2006
  2. Mr Not So Know It All

    Newbie question - User Controls and Events

    Mr Not So Know It All, Jan 12, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    383
    Mr Not So Know It All
    Jan 15, 2007
  3. =?Utf-8?B?cml2YWxAbmV3c2dyb3Vwcy5ub3NwYW0=?=

    Linking events from controls, when the controls have been created

    =?Utf-8?B?cml2YWxAbmV3c2dyb3Vwcy5ub3NwYW0=?=, Jul 16, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    611
    =?Utf-8?B?cml2YWxAbmV3c2dyb3Vwcy5ub3NwYW0=?=
    Jul 16, 2007
  4. SevDer
    Replies:
    2
    Views:
    1,332
    Walter Wang [MSFT]
    Nov 13, 2007
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    420
    Chris
    Aug 30, 2005
Loading...

Share This Page