problem in getting checked status ????

Last post 05-17-2008 11:44 AM by Samu Zhang - MSFT. 4 replies.

Sort Posts:

  • problem in getting checked status ????

    05-15-2008, 4:42 AM
    • Participant
      985 point Participant
    • SanjaySutar
    • Member since 06-19-2007, 2:49 AM
    • Posts 555

    Hi,
      i have a content page (derived from master page)  with 1 Datalist control which contains 1 RadioButton control in ItemTemplate
      and a Submit Button.
     
      On the click of submit button I want to output the selected RadioButton Checked State on the page.

      So i am writing the code as follows on the click of Submit Button:
         foreach (DataListItem itm in DataList1.Items)
            {
                GroupRadioButton selRadioButton = itm.FindControl("ctl00_ContentPlaceHolder1_DataList1_ctl00_RButton1") as GroupRadioButton;

                if ( selRadioButton !=null &&  selRadioButton.Checked == true)
                {
                    Response.Write(selRadioButton.Checked.ToString());
                }
            }


        The name of RadioButton which i found from html of rendered page (By Saying View Source from View Menu)
        is "ctl00_ContentPlaceHolder1_DataList1_ctl00_RButton1".
       
        But the above code is not working. I am always getting null.
       What's wrong here ???????

     Thanx in advance
     

  • Re: problem in getting checked status ????

    05-15-2008, 5:39 AM
    • Contributor
      2,298 point Contributor
    • Raggers
    • Member since 02-17-2006, 4:40 PM
    • Germany
    • Posts 388

    This should work....! Problem is you are trying to find control in server then why using client id of control .

    Whats this  GroupRadioButton  ....! Should be RadioButton or RadioButtonList I guess .Check the type of control properly

    foreach (DataListItem itm in DataList1.Items)
            {
                RadioButton selRadioButton = itm.FindControl("RButton1") as RadioButton;

                if ( selRadioButton !=null &&  selRadioButton.Checked == true)
                {
                    Response.Write(selRadioButton.Checked.ToString());
                }
            }

    If this solves your problem please mark as answer
  • Re: problem in getting checked status ????

    05-15-2008, 5:46 AM
    • Participant
      985 point Participant
    • SanjaySutar
    • Member since 06-19-2007, 2:49 AM
    • Posts 555

    GroupRadioButton is a usercontrol which derives from RadioButton.

     

  • Re: problem in getting checked status ????

    05-15-2008, 8:30 AM
    • Participant
      985 point Participant
    • SanjaySutar
    • Member since 06-19-2007, 2:49 AM
    • Posts 555

    Hi Thanx 4 the reply. The problem in fixed.

    But can u just tell me when to use ID like "ctl00_ContentPlaceHolder1_DataList1_ctl00_RButton1"

    and when to use  "RButton1" ?????????

  • Re: problem in getting checked status ????

    05-17-2008, 11:44 AM

     Hi SanjaySutar,

    SanjaySutar:

    But can u just tell me when to use ID like "ctl00_ContentPlaceHolder1_DataList1_ctl00_RButton1"

    and when to use  "RButton1" ?????????

     

    So , this is one concept question.

    Each web control will render itself as html tag, so we can see it in html page.

    For example: TextBox control <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> will be renderd as <input name="TextBox1" type="text" id="TextBox1" /> 

    Please notice that the ID="TextBox1" and id="TextBox1" are quite different. The first is used to identify the server control at server side , and the second is used to indentify the element at client side. If the control is in Container control, it's Clientid will be different from it's ID, just like your scenario.

    Clientid will be use if you want to write some javascript code to do some operation. ID will be used at codebehind.

     


    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Page 1 of 1 (5 items)