Skip to main content

Microsoft Silverlight

Answered Question texthtml.SetAttribute("visible", "false") PROBLEMRSS Feed

(0)

Fab281085
Fab281085

Member

Member

30 points

22 Posts

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

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 

Yuri Zholobov
Yuri Zho...

Member

Member

266 points

75 Posts

Re: texthtml.SetAttribute("visible", "false") PROBLEM

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.

-- Yuri Zholobov, [MCPD:EAD, MCPID 3749109], MS Team

Fab281085
Fab281085

Member

Member

30 points

22 Posts

Re: texthtml.SetAttribute("visible", "false") PROBLEM

Ok thank and if I want to re-show it again? 

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

Yuri Zholobov
Yuri Zho...

Member

Member

266 points

75 Posts

Re: texthtml.SetAttribute("visible", "false") PROBLEM

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,

-- Yuri Zholobov, [MCPD:EAD, MCPID 3749109], MS Team

Fab281085
Fab281085

Member

Member

30 points

22 Posts

Re: texthtml.SetAttribute("visible", "false") PROBLEM

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
 

Yuri Zholobov
Yuri Zho...

Member

Member

266 points

75 Posts

Re: Re: texthtml.SetAttribute(&quot;visible&quot;, &quot;false&quot;) PROBLEM

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. :)

-- Yuri Zholobov, [MCPD:EAD, MCPID 3749109], MS Team

Fab281085
Fab281085

Member

Member

30 points

22 Posts

Re: Re: texthtml.SetAttribute(&quot;visible&quot;, &quot;false&quot;) PROBLEM

 But I haven't a CSS class

Yuri Zholobov
Yuri Zho...

Member

Member

266 points

75 Posts

Re: Re: texthtml.SetAttribute(&quot;visible&quot;, &quot;false&quot;) PROBLEM

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.

-- Yuri Zholobov, [MCPD:EAD, MCPID 3749109], MS Team

dave_el
dave_el

Member

Member

24 points

16 Posts

Re: texthtml.SetAttribute("visible", "false") PROBLEM

 what about texthtml.Visibility = Visibility.Collapsed; (or Visible).

Fab281085
Fab281085

Member

Member

30 points

22 Posts

Re: Re: texthtml.SetAttribute(&quot;visible&quot;, &quot;false&quot;) PROBLEM

Yuri Zholobov:

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. 

Fab281085
Fab281085

Member

Member

30 points

22 Posts

Re: Re: texthtml.SetAttribute(&quot;visible&quot;, &quot;false&quot;) PROBLEM

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? 

Yuri Zholobov
Yuri Zho...

Member

Member

266 points

75 Posts

Re: Re: texthtml.SetAttribute(&quot;visible&quot;, &quot;false&quot;) PROBLEM

Fab281085:
Nothing.

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

-- Yuri Zholobov, [MCPD:EAD, MCPID 3749109], MS Team

Fab281085
Fab281085

Member

Member

30 points

22 Posts

Re: Re: texthtml.SetAttribute(&quot;visible&quot;, &quot;false&quot;) PROBLEM

why not...thanks! 

Yuri Zholobov
Yuri Zho...

Member

Member

266 points

75 Posts

Answered Question

Re: Re: Re: texthtml.SetAttribute(&amp;quot;visible&amp;quot;, &amp;quot;false&amp;quot;) PROBLEM

Check this: http://demo.themsteam.com/misc/sample-Fab281085-SetAttributeProblem.zip

-- Yuri Zholobov, [MCPD:EAD, MCPID 3749109], MS Team
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities