none
texthtml.SetAttribute("visible", "false") PROBLEM

    Question

  • Hi.

    I have a problem wiht an HTML element, I want to hide this element and show it only after a click on a xaml button.

    In public void Page_Loaded(object o, EventArgs e) I put this code:

    texthtml.SetAttribute("visible", "false");

    but when my application starts the HTML element is visible.

    Can someone help me?

    FB 

    Monday, January 14, 2008 9:39 AM

All replies

  • You need to change this to

    texthtml.SetStyleAttribute("display", "none");

    Be aware, however, that this will set a CSS style directly on the HTML element. So all the CSS applying rules will work here. For example, if the HTML element is also assigned a CSS class and even if in that CSS class "display" is defined, the direct CSS style will override the CSS class and the element will remain invisible.

    Monday, January 14, 2008 10:18 AM
  • Ok thank and if I want to re-show it again? 

    texthtml.SetStyleAttribute("display", "???????????");

    Monday, January 14, 2008 11:38 AM
  • See http://www.w3.org/TR/CSS1#display for specs on "display". For example for div it will be "block".

    Please also note the line in specs: "UAs may ignore 'display' and use only the UA's default values." This means that some browsers may, depending on settings or user preferences, show the element even if you set "display:none" on it. This may or may not be what you need. For example if the hidden element is hidden for visual design reasons, to conserve space - like an "Add Comment" link which, when clicked, makes a comment box visible - then you have no problem. But if hidden element is hidden due to application logic - for example you have two elements representing mutually-exclusive data depending on state of a checkbox - then this may be a problem. In case of application logic reason to hide the element I would recommend to physically create/delete element dynamically or better reload page (postback) or part of page (partial postback - e.g. using AJAX) instead of just hiding element using CSS.

    By the way, the "display:none" hides element including the box around it, so the space on page where element was situated no longer exists at all. If this is not suitable for your HTML formatting then you can also look into "visibility" property (http://www.w3schools.com/css/pr_class_visibility.asp) - it preserves formatting space for invisible element,

    Monday, January 14, 2008 12:02 PM
  • This is the definition of my textbox in my TestPage.html:

    <input id="textbox" type="text" style="position: absolute; left: 480px; top: 230px; width: 192px; height: 15px; z-index:10000"/>

     If I put in Page.xaml.cs this code: texthtml.SetStyleAttribute("display", "none");  in the function Page_Loaded when I start my application the textbox isn't hide.

    If i put diplay:none in the defeinition in the html file, the textbox is hide but I can't show it again!!!

    Can someone help me?

     

     

    FB
     

    Monday, January 14, 2008 1:06 PM
  • Try to move inline "style" into a CSS class and assign the class to the "input" using "class" attribute. Then setting "display" in Page_Load should work. I cannot check this now since I'm not at work, so this is just theoretical suggestion. :)

    Monday, January 14, 2008 1:15 PM
  •  But I haven't a CSS class

    Monday, January 14, 2008 1:20 PM
  • I meant that if you have HTML like this:

    <html>
    <head>
    </head>
    <body>
    <input id="textbox" type="text" style="position: absolute; left: 480px; top: 230px; width: 192px; height: 15px; z-index:10000"/>
    </body>
    </html>

    Replace it with HTML like this:

    <html>
    <head>
    <style type="text/css">
    <!--
    .myinput
    {
    position: absolute;
    left: 480px;
    top: 230px;
    width: 192px;
    height: 15px;
    z-index:10000;
    }
    -->
    </style>
    </head>
    <body>
    <input id="textbox" type="text" class="myinput"/>
    </body>
    </html>

    And then try again setting "display" in Page_Load.

    Monday, January 14, 2008 1:32 PM
  •  what about texthtml.Visibility = Visibility.Collapsed; (or Visible).

    Monday, January 14, 2008 1:37 PM
  • I meant that if you have HTML like this:

    <html>
    <head>
    </head>
    <body>
    <input id="textbox" type="text" style="position: absolute; left: 480px; top: 230px; width: 192px; height: 15px; z-index:10000"/>
    </body>
    </html>

    Replace it with HTML like this:

    <html>
    <head>
    <style type="text/css">
    <!--
    .myinput
    {
    position: absolute;
    left: 480px;
    top: 230px;
    width: 192px;
    height: 15px;
    z-index:10000;
    }
    -->
    </style>
    </head>
    <body>
    <input id="textbox" type="text" class="myinput"/>
    </body>
    </html>

    And then try again setting "display" in Page_Load.

     

     

    Nothing.

    And htmltext.Visibility doesn't exist. 

    Monday, January 14, 2008 2:39 PM
  • I am using an html input textbox because i want that the user put the data in my application. There is another method to receive data from users? 

    Tuesday, January 15, 2008 4:18 AM
  • Nothing.

    I just wrote a sample and it works like a charm. Do you want the sample which works exactly like I suggested?

    Tuesday, January 15, 2008 4:34 AM
  • why not...thanks! 

    Tuesday, January 15, 2008 4:46 AM