In ASP. NET pages, this method is usually used to control the invisibility of some elements:
<% IF (this. Show edit panel) {%>
...... HtmlCode......
<% }%>
This method is convenient, but if you want to use it in the server control template to determine a property of the bound object, an error will be returned:
<% IF (eval ("Default photo ")! = NULL) {%>
...... HTML code to be displayed ......
<% }%>
Because our code is written in <% ...... To get the attributes of the currently bound object, write the code to <% #...... %>, But this modification is not correct:
<% # If (eval ("Default photo ")! = NULL) {%>
...... HTML code to be displayed ......
<% }%>
So what should we do? The following three methods are provided:
Determine and output text directly in embedded code:
<% # (Bool) eval ("use as default photo ")? "Current default image": String. Empty %>
This method is applicable when only text is output. Note: "Use as default photo" is a bool type attribute of the currently bound object.
Embed code in the visible attribute of the server control for judgment:
<Asp: button id = "button1" runat = "server" text = "set as default image" commandname = "setdefaultimage" visible = '<% #! (Bool) eval ("use as default photo") %> '/>
This method is applicable when you only need to control the invisibility of a single control. Note: "Use as default photo" is a bool type attribute of the currently bound object.
The placeholder control is used to load multiple elements as a container, and the code embedded in its visible attribute controls the hiding of multiple elements inside the container:
<Asp: placeholder id = "placeholder1" runat = "server" visible = '<% # eval ("Default photo ")! = NULL %> '> default photo: <a target =' _ blank 'Title =' click to open the original size image 'href = '<% # eval ("Default photo. full-size graph file path ") %> '>
'/>
<Br/> </ASP: placeholder>
This method is applicable when multiple elements need to be controlled simultaneously. Note: The "Default photo" is a custom property of the currently bound object.
Download the XPS version of this article: