Display hiding methods for controls

Source: Internet
Author: User

But the guarantee does not jump page, can Baidu this effect is after jump. In other words, I had to make two sets of effects on the same page, so I thought about the implementation of the control's explicit concealment. After exploring, there are two ways to solve this problem:

One, using the panel as a container can use the ASP Control Panel as a container, and then use other ASP control with the implementation, this is the most convenient, the code is as follows:
Panel1: [HTML]View PlainCopy 
  1. <span style=><asp:panel ID=< Span class= "Attribute-value" > "Panel1"  runat= "server"  font-size= "Medium" >   
  2.      <span  id= "SayHello" > Hello, <span><%=session["UserName"] % ></span> </span>  
  3.      <asp:HyperLink  id= "hlpersonalspace"  runat= "server"  navigateurl= "~/needhelpspace.aspx"  target= "_self" > personal space </asp:hyperlink>   
  4. <asp:hyperlink id="Hlinfo" runat="Server"> Message </asp:hyperlink>
  5. <Asp:linkbutton id="Hlquit" runat="Server" onclick="Hlquit_click " > Exit </Asp:linkbutton>
  6. </asp:panel></span>

Panel2:

[HTML]View PlainCopy 
  1. <span style="FONT-SIZE:14PX;"  ><asp:panel id="Panel2" runat="Server" font-size="Medium">
  2. Hello, visitor.
  3.        <a  href= "#"  onclick= "$ (' #w '). Window (' open ')" > login </ a>   
  4.        <asp:HyperLink  id= "Hlregister"  runat= "server"  navigateurl= ~/ Register.aspx " target=" _blank " > Register </asp:hyperlink>     
  5. <asp:hyperlink id="Hlsearch" runat="Server"> Help </asp:hyperlink >
  6. </asp:panel></span>


Background code:

[CSharp]View PlainCopy  
  1. <span style="FONT-SIZE:14PX;" > if (session["UserName"] = = null)
  2. {
  3. Panel2.visible = true;
  4. Panel1.visible = false;
  5. }
  6. Else
  7. {
  8. Panel1.visible = true;
  9. Panel2.visible = false;
  10. }</span>

Second, use Div as container

But I am here because of the use of the master, and the ASP control must be placed in the server-side form, this may cause a conflict with the child page, resulting in a page with two server-side form. Therefore, the HTML control needs to be changed. The way I use it here is to put the relevant HTML controls and tags in the div, but the div must add runat= "Server" before interacting with the background. You can also use JS directly to the DIV's explicit control, the code is as follows:

DIV1:

[HTML]View PlainCopy
  1. <span style="FONT-SIZE:14PX;" ><div id="Loginbefore" runat ="Server" style="Font-size:medium" >
  2. <span id= "topuser" style="padding-right:25px;" > Hello tourists
  3. <a href="javascript:void (0)" onclick="$ (' #w '). Window (' open ') '> Login </A >
  4. <a href="register.aspx"> Register </a>
  5. <a href="#"> Search </a>
  6. </span>
  7. </div></span>

DIV2:

[HTML]View PlainCopy
  1. <span style="FONT-SIZE:14PX;" ><div id= "loginafter" runat= "server" style= "font-size:medium " >
  2.            < span id= "TopUser1"  < span class= "attribute" >style= "padding-right:25px;" > Hello, <span> <%=session["UserName"] %></ span> |   
  3. <a href= "userloglist.aspx?id=<%=session[" UserID"]%>" > Personal Space </a    > |
  4. <a href="unreademail.aspx"> Message </a> |
  5. <a href="#" onclick="Loginquit ()"> Exit </a>
  6. </span>
  7. </div></span>

C # Background Call method:

[HTML]View PlainCopy
  1. <span style="FONT-SIZE:14PX;" > if (session["UserName"] = = null)
  2. {
  3. loginbefore.style["Display"] = "Block";
  4. loginafter.style["Display"] = "None";
  5. }
  6. Else
  7. {
  8. loginbefore.style["Display"] = "None";
  9. loginafter.style["Display"] = "Block";
  10. }
  11. </span>


If you use JS to call directly, you can manipulate the method of Div explicit is as follows:

[HTML]View PlainCopy
    1. <span style="FONT-SIZE:14PX;" > document.getElementById ("Loginafter"). Style.display = "None";//Hide
    2. document.getElementById ("Loginbefore"). Style.display = "block";//Display </span>

The effect of the final implementation is as follows:

Figure 3: Before landing

Figure 4: After landing

Display hiding methods for controls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.