Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 732
  • Last Modified:

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.
0
amillyard
Asked:
amillyard
  • 5
  • 3
1 Solution
 
bullroutCommented:
HI There,

Have you tried to use the pre-render on the control?

http://msdn2.microsoft.com/en-us/library/system.web.ui.control.prerender.aspx

Hope this helps
0
 
amillyardAuthor Commented:
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.
0
 
divinewind80Commented:
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.
0
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 
amillyardAuthor Commented:
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.
0
 
amillyardAuthor Commented:
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,
0
 
bullroutCommented:
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)
0
 
amillyardAuthor Commented:
@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"];
0
 
bullroutCommented:
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
0
 
amillyardAuthor Commented:
@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;
            }
        }
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now