相关文章推荐
有情有义的蟠桃  ·  NEWSEQUENTIALID ...·  1 年前    · 
A Default.aspx page has some controls. Some controls visibility depends upon conditions. Here, what is tend to accomplish is change the visible property at runtime depending upon the conditional value.
Sampel Markup (Default.aspx in Static Mode)
< div id =" DivBtnImgCopy" runat =" server" Visible = " True" > < asp:ImageButton ID =" BtnImgCopy" CssClass =" image" ToolTip =" Copy Mode" ImageUrl =" img/tlb_img_copy.gif" runat =" server" OnClientClick =" CopyImage(); SelectButton(this,true);return false;" / > What I tried is write a method in code behind file and tried to get value from that method to set visible property to true or false.
CodeBehindFile (Default.aspx.cs)
protected bool ShowHideButton() bool bStatus = false ; if (sCondition == " false" ) bStatus = false ; else if (sCondition == " true" ) bStatus = true ; return bStatus; catch { } Sample Markup (Default.aspx in Dynamic Mode)
< div id =" DivBtnImgCopy" runat =" server" visible = " <% =ShowHideButton() %>" > < asp:ImageButton ID =" BtnCopy" ToolTip =" Copy Mode" ImageUrl =" img/tlb_img_copy.gif" runat =" server" / > But, Getting below error: Cannot create an object of type 'System.Boolean' from its string representation '<%=ShowHideButton() %>' for the 'Visible' property.
Any solution or work-around to accomplish this task. Need Help. <div id= " DivBtnImgCopy" runat= " server" visible= " <%# ShowHideButton()%>" > <asp:ImageButton ID= " BtnCopy" ToolTip= " Copy Mode" ImageUrl= " img/tlb_img_copy.gif" runat= " server" /> </ div >
And update code behind as below.
protected bool ShowHideButton() bool bStatus = false ; if (sCondition == " false" ) bStatus = false ; else if (sCondition == " true" ) bStatus = true ; catch { } return bStatus; Hope this will work. <div id= " DivBtnImgCopy" > <asp:ImageButton ID= " BtnCopy" ToolTip= " Copy Mode" ImageUrl= " img/tlb_img_copy.gif" runat= " server" /> </ div > <script type= " text/javascript" > document.getElementById( " DivBtnImgCopy" ).style.display = " <%=ShowHideButton() %>" ; </script>
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •