RadioButton: REALLY URGENT!! 
Author Message
 RadioButton: REALLY URGENT!!

Hi List,

I've been stuck with this problem since a really long time -
please help me out.

Pleeeeeeeeaaaaaaaasssssseeeeeeee do reply back really fast.

First of all, I wanted to add a RadioButton column to a
DataGrid, and I was not able to do this because DataGrid
implements the INamingContainer interface and automatically
appends the UniqueID of each RadioButton to the "Name"
attribute in the rendered HTML. Therefore, even if I set
the GroupName property of all these RadioButtons to be the
same, the final "Name" property in the HTML was something
like "ctl.._ctl.._...GroupName", and therefore the browser
took all these RadioButtons as belonging to differnt groups.

As a solution, I wrote my own RadioButton inheriting from
System.Web.UI.WebControls.RadioButton, and overrode the
UniqueID property - I simply returned
(base.UniqueID).substring(0, (base.UniqueID).lastindex(":")

And it worked neatly after that. I just mentioned this part
because it might have a relation to the problem where I am
now stuck up.

I have actually made a WebControl which contains a DataGrid
besides many other things, and this DataGrid contains the
RadioButtons. I try to access the Checked property of these
RadioButtons in the OnLoad() method, but all of them come
out to be false. Please also have a look at:

http://www.*-*-*.com/

Alex came up with similar problems, but he was able to
solve it by changing the order in which the controls were
rendered. In my case, I cannot do this because the
RadioButtons are inside the WebControl that I am making.

Any suggesstions? I hate doing this but I'll try adding some
client-side JavaScript and see if I can transfer these
values to some other invisible control which retains its
values in the OnLoad() on the server-side.

Thanks a lot in advance,
Aaditeshwar.

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!



Mon, 13 Dec 2004 21:27:23 GMT  
 RadioButton: REALLY URGENT!!
Hi,

i had a similar problem that's now solved, the check boxes in the datagrid
were always read as false just because of the absence of :
EnableViewState=True

i send you parts of the source code to see if it ressembles to what you've
done :

the datagrid was like this :

  <asp:datagrid id="datagridAttachment" runat="server"
AutoGenerateColumns="False" Width="500px">
     <Columns>
      <asp:TemplateColumn HeaderText="Messages attachment">
       <HeaderStyle CssClass="DataListHeaderLink"></HeaderStyle>
       <ItemStyle CssClass="DataListText"></ItemStyle>
       <ItemTemplate>
*****here is the interesting line :
        <asp:CheckBox EnableViewState=True id='chkAttach' runat='server'
Text='<%# DataBinder.Eval(Container.DataItem, "attachment")%>'>
        </asp:CheckBox>
       </ItemTemplate>
      </asp:TemplateColumn>
     </Columns>
     <Columns>
      <asp:TemplateColumn>
       <HeaderStyle CssClass="DataListHeaderLink"></HeaderStyle>
       <ItemStyle CssClass="DataListText"></ItemStyle>
       <ItemTemplate>
        <asp:label id="lblMsgLabel" runat="server" CssClass="DataListText">
         <%# DataBinder.Eval(Container.DataItem, "forummessagelabel") %>
        </asp:label>
       </ItemTemplate>
      </asp:TemplateColumn>
     </Columns>
    </asp:datagrid>

and the way to read it was
protected System.Web.UI.WebControls.DataGrid datagridAttachment;
for (int i=0; i<datagridAttachment.Items.Count; i++)
   {
    DataGridItem _item = datagridAttachment.Items[i];
    CheckBox chkAttach = (CheckBox)_item.FindControl("chkAttach");

    if( chkAttach.Checked )
    {
            /*your code*/
    }
   }

these are fragments of the code, so some variable definitions are missing,
but it's to give you a fast answer, contact me if you need more information.

Benoit Joassart


Quote:

> Hi List,

> I've been stuck with this problem since a really long time -
> please help me out.

> Pleeeeeeeeaaaaaaaasssssseeeeeeee do reply back really fast.

> First of all, I wanted to add a RadioButton column to a
> DataGrid, and I was not able to do this because DataGrid
> implements the INamingContainer interface and automatically
> appends the UniqueID of each RadioButton to the "Name"
> attribute in the rendered HTML. Therefore, even if I set
> the GroupName property of all these RadioButtons to be the
> same, the final "Name" property in the HTML was something
> like "ctl.._ctl.._...GroupName", and therefore the browser
> took all these RadioButtons as belonging to differnt groups.

> As a solution, I wrote my own RadioButton inheriting from
> System.Web.UI.WebControls.RadioButton, and overrode the
> UniqueID property - I simply returned
> (base.UniqueID).substring(0, (base.UniqueID).lastindex(":")

> And it worked neatly after that. I just mentioned this part
> because it might have a relation to the problem where I am
> now stuck up.

> I have actually made a WebControl which contains a DataGrid
> besides many other things, and this DataGrid contains the
> RadioButtons. I try to access the Checked property of these
> RadioButtons in the OnLoad() method, but all of them come
> out to be false. Please also have a look at:

> http://www.dotnet247.com/247reference/msgs/17/85005.aspx

> Alex came up with similar problems, but he was able to
> solve it by changing the order in which the controls were
> rendered. In my case, I cannot do this because the
> RadioButtons are inside the WebControl that I am making.

> Any suggesstions? I hate doing this but I'll try adding some
> client-side JavaScript and see if I can transfer these
> values to some other invisible control which retains its
> values in the OnLoad() on the server-side.

> Thanks a lot in advance,
> Aaditeshwar.

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Mon, 13 Dec 2004 23:08:23 GMT  
 RadioButton: REALLY URGENT!!

Hi Benoit,

Thanks a lot for the reply. I thought that ViewState was
enabled by default and so I didn't try your really simple
method before.

I got around by a more complicated procedure. I added a
TextBox and made it invisible. Then I added some Javascript
to each of the RadioButtons:

btn.Attributes.Add
("onclick", "btnelem=document.getElementById(\"" +btnID+
"\"); textelem=document.getElementById(\"" +textID+ "\");
textelem.value=btnelem.checked;");

This also solved another problem because now I was able to
add a RequiredFieldValidator to this TextBox, and hence I
made it imperative to select a RadioButton always.

Thanks a lot!

Best Regards,
Aaditeshwar.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Tue, 14 Dec 2004 00:44:42 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. really really dumb question

2. I really really want to turn off warnings in eVC4 SP1

3. Help With Casting A Control Item To RadioButton

4. RadioButton group binding?

5. Default RadioButton Question

6. RADIOBUTTON BOX SIZE

7. RadioButton

8. Subclassed RadioButton hanging when clicked!

9. Radiobutton visible/unvisible

10. Strange RadioButton Hanging Problem!

11. Subclassed RadioButton hanging when clicked?!

12. Q: Getting status of RadioButton

 

 
Powered by phpBB® Forum Software