SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to make Label control visible....hard time to do that

    Hello folks,

    I have a master-content form.

    All the controls on the content form are server control.
    When clicked on button control, a label control should become visible.

    I have read the article at http://www.vanseodesign.com/css/visibility-vs-display/

    But I still can't make it visible. Here is the code so far. Could someone let me know my mistake?

    Code:
    <%@ Page Title="" Language="C#" MasterPageFile="~/SiteMasterPage.master" AutoEventWireup="true" CodeFile="DynamicTextboxControls.aspx.cs" Inherits="DynamicTextboxControls" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
        
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <h3>Dynamic Textbox Controls</h3>
    <fieldset style="width: 300px">
            <legend>From</legend>
            
                <asp:RadioButtonList ID="RadioButtonList1" runat="server">
                    <asp:ListItem>Database</asp:ListItem>  
                    <asp:ListItem>Interactive</asp:ListItem>  
                </asp:RadioButtonList>            
                
        </fieldset>
         
         
            <table border="1">
                <tr> 
                    <td class="style1"><asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="Validate();"/>
                    </td>
                </tr>
            </table>
         
         
            <asp:Label runat="server" id="Label1" style="display: none;" />   
        
        
        
        <script type="text/javascript" language="javascript">
    
            function Validate() {
    
                document.getElementById("<%=Label1.ClientID%>").style.display = "visible";           
    
    
                         
            }
        </script>
    </asp:Content>
    Thanks much

  2. #2
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,107
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    Hi,

    display: visible; isn't a correct CSS value.
    You want to make this display: block;

    http://reference.sitepoint.com/css/display

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mark,

    All I changed after your suggestion was the following.
    function Validate() {

    document.getElementById("<%=Label1.ClientID%>").style.display = "block";
    }
    The label control shows up when I click on the button. But it disappears right away. I don't know why. When I click the button again, it displays for a second that's all.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the design time, the Label control's visible property has been set to True.

    In the page load event I made it hidden. My idea is when clicked on Button control, the above code should make the label control visible. It is making visible but the label control disappears immediately. Don't know why it disappears

    protected void Page_Load(object sender, EventArgs e)
    {

    Label1.Style.Add("visibility", "hidden");
    }

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what I found so far.

    If I use a HTML button control intead of using button asp control, it works fine (meaning the label control doesn't disappear). But if I use asp button control, the momement I click on button control, the label appears and it disappears...looks like I should somehow tell the asp button control not to invoke the server side event of that control...

    any suggestions on how to do this?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •