Link to home
Start Free TrialLog in
Avatar of amillyard
amillyardFlag for United Kingdom of Great Britain and Northern Ireland

asked on

drop-down control visibility affected by postback

Development Platform: c#, asp.net 2.x, Visual Studio Pro utilising Web Developer, IIS6, SQL Server 2005

Script below makes the drop-down list appear or disappear depending on which radio button is selected.

This is working as is...the issue I am trying to resolve is that when this page has a post back ... and the radio button 1 (left side) is selected, when the page refreshed (from the postback), this script does not 'hide' the drop down menu as before -- so everything is displayed.


<td style="width: 366px">
                            <asp:RadioButton ID="RadioButton1" runat="server" Font-Size="X-Small" GroupName="PipelineSpoolerTask" Text="Role" onclick="document.getElementById('DropDownList_StaffMembers').style.visibility = 'hidden';"/>
                            <asp:RadioButton ID="RadioButton2" runat="server" Font-Size="X-Small" GroupName="PipelineSpoolerTask" Text="Staff Member" onclick="document.getElementById('DropDownList_StaffMembers').style.visibility = 'visible';" Checked="True" />&nbsp;
                            <asp:DropDownList ID="DropDownList_StaffMembers" runat="server" DataSourceID="SqlDataSource_StaffMembers"
                                DataTextField="DisplayName" DataValueField="CompanyAgent_ID">
                            </asp:DropDownList>
                        </td>


your time and efforts with this enquiry are much apprieated.
ASKER CERTIFIED SOLUTION
Avatar of bullrout
bullrout

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of amillyard

ASKER

ok, have read through this article -- this definately appears to be the issue and the control to resolve it.

the only script reference on this article was as follows:

public event EventHandler PreRender

how do I implement this prerender control?

many thanks.
Avatar of divinewind80
divinewind80

This might assist some (it explains some about event handlers, in more detail):

http://www.dotnetjohn.com/articles.aspx?articleid=62

Ask if you have more questions.
have read through the article supplied.

could you kindly provide some sample code that relates to the above scripting, so I could see this working and in context.
I seem to get a measured results by using the following:

        protected void Page_PreRender(object sender, EventArgs e)
        {
            RadioButton_Role.Checked = false;
            RadioButton_StaffMember.Checked = true;
        }


the above simply reset the radio buttons to their original position -- but obviously does retain their user adjusted position during form updating...how would I preserved these positions during the page-update -- so I don't have to create more 'Session' variables etc.

many thanks,
HI There,

sorry for the late reply. one possible solution is. You can use view state to rememeber values like:

I have not tested this so you will need to check the syntax but you get the idea...

       public bool _isChecked
        {
            get
            {
                if (ViewState["_isChecked"] == null)
                {
                    return false;
                }
                else
                {
                    return bool.Parse(ViewState["_isChecked"];
                }
            }
            set
            {
                ViewState["_isChecked"] = value;
            }
        }


ViewState["_isChecked"] = (my checked checkbox)
@bullrout : apprieate your response.

the only compiler error I am getting is as follows:

"cannot convert from 'object' to 'string'"

for the line:  return bool.Parse(ViewState["_isChecked"];
Hi,
post the whole code please, I', going to be now but I will sort it tomorrow. make sure that it's vs 2005 sp1that you're using.

Sean
@bullrout : thank you for all your contributions, I did manage to resolve the last part in the end (did apprieate your commitment to try and resolve, which I'm sure you could have done).  you pointed me in the right direction for sure, which made a solution possibe.

fyi -- the working script for reference as follows:


        protected void Page_PreRender(object sender, EventArgs e)
        {
            ViewState["_isChecked"] = RadioButton_Role.Checked;

            if (Convert.ToBoolean(ViewState["_isChecked"]))
            {
                RadioButton_Role.Checked = true;
                RadioButton_StaffMember.Checked = false;
            }
            else
            {
                RadioButton_Role.Checked = false;
                RadioButton_StaffMember.Checked = true;
            }
        }

        public bool _isChecked
        {
            get
            {
                if (ViewState["_isChecked"] == null)
                {
                    return false;
                }
                else
                {
                    return (ViewState["_isChecked"] == "true");
                    //return bool.Parse((string)ViewState["_isChecked"]);
                }
            }
            set
            {
                ViewState["_isChecked"] = value;
            }
        }