Re: radioButton and pannels

"Shanmugam, Kris" <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.web
Message-ID <3DC4616854D6A84884BCB5FC545B35748A721D@usplm203.amer.corp.eds.com>
The visibility of the panels can be toggled on the client side and you
can disable the AutoPostBack:

A script similar to the following can be used:

/// <summary>
/// Script used to toggle the panel visibility.
/// </summary>
private void TogglePanelScript ()
{
        StringBuilder sbScript = new StringBuilder();
        sbScript.AppendFormat("<script type='text/javascript'>{0}",
Environment.NewLine);
        sbScript.AppendFormat("function TogglePanel(panel,
radControl){0}", Environment.NewLine);
        sbScript.Append("{");
        sbScript.AppendFormat("{0}if (radControl.checked == true)",
Environment.NewLine);
        sbScript.Append("{");
        sbScript.AppendFormat("{0}panel.style.display = 'inline';{0}",
Environment.NewLine);
        sbScript.Append("}");
        sbScript.AppendFormat("{0}else{0}", Environment.NewLine);
        sbScript.Append("{");
        sbScript.AppendFormat("{0}panel.style.display = 'none';{0}",
Environment.NewLine);
        sbScript.Append("}");
        sbScript.Append(Environment.NewLine);
        sbScript.Append("}");
        sbScript.AppendFormat("{0}</script>", Environment.NewLine);
        Type csType = this.GetType();
        ClientScript.RegisterStartupScript(csType, "Panels",
sbScript.ToString());
} 

And set the radio button attributes.
E.g.:
        radDisputeYes.Attributes.Add("onClick",
string.Format("TogglePanel(pnlDispute, {0})", radDisputeYes.ClientID));
        radDisputeNo.Attributes.Add("onClick",
string.Format("TogglePanel(pnlDispute, {0})", radDisputeYes.ClientID));

The above was used in a ASP.Net 1.1 application and upgraded to 2.0. I
think there is a better way to do it in VS 2005 especially for wizard
type forms.

Kris

-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
[mailto:[email protected]] On Behalf Of Patrick Newberry
Sent: Tuesday, March 13, 2007 1:42 PM
To: [email protected]
Subject: [DOTNET-WEB] radioButton and pannels

I have a situation where there are three radio buttons on a page:

The user is to click one of the buttons and then based on what the user
clicks certain combinations of text and form fields should appear. 

My idea was to use panels and to set the visability property based on
which radio button was pushed via  AutoPostBack="True". 

The bad news is that the page is sort of long and when I do the call
back attached to the radio buttons the page reloads and I am back to the
top of the page and you have to scroll back down the page to get to
where  you left off. Other than that this would seem to be a good option
(ignoring the call back cycle)

One small factor: this page is part of a multipage wizard e.g.

            <WizardSteps>
                <asp:WizardStep....


Any suggestions as to the best way to dynamically change a page (setting
panels to visible or not visiable based on a radio button value while in
the middle of long page. (or other non pannel options.)




Asp version Code:

<asp:RadioButton id="opition_one" Text="text for option one"
                                 AutoPostBack="True" 
                                 OnCheckedChanged="Get_Checked_Button"
GroupName="tithe" runat="server"/>
                            <br />     

<asp:RadioButton id="option_two" Text="text for option two"
                                 AutoPostBack="True"
                                 OnCheckedChanged="Get_Checked_Button"
GroupName="tithe" runat="server"/>
                            <br />

<asp:RadioButton id="option three" Text="text for option three"
                                 AutoPostBack="True"
                                 OnCheckedChanged="Get_Checked_Button"
GroupName="tithe" runat="server" />    
                                 
                                                            
                             <br />
                             
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px">
                             Form fields and text goes here

                            </asp:Panel>
                            
<asp:Panel ID="Panel2" runat="server" Height="50px" Width="125px">
                             Form fields and text goes here
                             
                            </asp:Panel>
                            
<asp:Panel ID="Panel3 runat="server" Height="50px" Width="125px">
                             Form fields and text goes here

                            </asp:Panel>


Pat Newberry
www.gypsyfarm.com

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.