aspx 페이지의 if 문
변수가 true로 설정되었는지 여부에 따라 항목 1 또는 항목 2를 표시하도록 사이트에 기본 if 문을 작성하고 싶습니다.
.NET에 너무 익숙하지 않으며 aspx 페이지에서 작동하도록 if 문을 가져 오는 방법의 기본 구조에 대한 약간의 도움이 필요합니다.
페이지의 일부를 표시하거나 숨기는 것이 목적이라면 다음 작업을 수행 할 수 있습니다.
1) 마크 업으로 감싸
<% if(somecondition) { %>
some html
<% } %>
2) Panel 컨트롤에서 파트를 감싸고 코드 숨김에서 if 문을 사용하여 Panel의 Visible 속성을 설정합니다.
간단한 코드 사용
<%
if(condition)
{%>
html code
<% }
else
{
%>
html code
<% } %>
일반적으로 당신은 단지의 코드를 다루고 싶어요 Page_Load
당신의 .aspx
페이지의 코드 숨김.
if (someVar) {
Item1.Visible = true;
Item2.Visible = false;
} else {
Item1.Visible = false;
Item2.Visible = true;
}
이것은 당신이있어 가정 Item1
하고 Item2
이미 페이지에 배치.
<div>
<%
if (true)
{
%>
<div>
Show true content
</div>
<%
}
else
{
%>
<div>
Show false content
</div>
<%
}
%>
</div>
마스터 페이지를 사용하는 VB.NET aspx 페이지의 헤더에있는 선택적 콘텐츠에 대한 완전한 답변 :
<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="some_vb_page.aspx.vb" Inherits="some_vb_page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<% If Request.QueryString("id_query_param") = 123 Then 'Add some VB comment here,
'which will not be visible in the rendered source code of the aspx page later %>
<!-- add some html content depending on -->
<!-- the condition in the if statement: -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<% End If %>
</asp:Content>
Where your current page url is something like:
http://mywebpage.com/some_vb_page.aspx?id_query_param=123
To use C# (C# Script was initialized at 2015) on ASPX page you can make use the following syntax.
Start Tag:- <%
End tag:- %>
Please make sure that all the C# code must reside inside this <%%>
.
Syntax Example:-
<%@ Import Namespace="System.Web.UI.WebControls" %>
(For importing Namespace) Reference to some basic namespaces for working with ASPX page.<%@ Import Namespace="System.Web.UI.WebControls" %> <%@ Import Namespace="System.Diagnostics" %> <%@ Import Namespace="System" %> <%@ Import Namespace="System.Web" %> <%@ Import Namespace="System.Web.UI" %> <%@ Import Namespace="System.IO" %>
C# Code:-
`<%
if (Session["New"] != null)
{
Page.Title = ActionController.GetName(Session["New"].ToString());
}
%>`
Features of C# Script:
- No need of compilation. Run time execution is occurred like Java Script.
Before using C# script make sure the following things:-
- You are on WebForm. Not on WebForm with master page.
- If you are in WebForm with master page make sure that you have written your C# script at Master page file.
C# script can be inserted anywhere in the aspx page but after the page meta declaration like
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Profile.master.cs" Inherits="OOSDDemo.Profile" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication3.WebForm1" %>
(For WebForm)
Here's a simple one written in VB for an ASPX page:
If myVar > 1 Then
response.write("Greater than 1")
else
response.write("Not!")
End If
C#
if (condition)
statement;
else
statement;
vb.net
If [Condition] Then
Statement
Else
Statement
End If
If else examples with source code... If..else in Asp.Net
Patter
참고URL : https://stackoverflow.com/questions/3063436/if-statement-in-aspx-page
'programing tip' 카테고리의 다른 글
열거 형이 Swift의 프로토콜을 준수하도록 만드는 방법은 무엇입니까? (0) | 2020.09.09 |
---|---|
LINQ Distinct 연산자, 대소 문자 무시? (0) | 2020.09.09 |
일시적으로 auto_now / auto_now_add 비활성화 (0) | 2020.09.09 |
불법 배포로부터 소프트웨어를 어떻게 보호합니까? (0) | 2020.09.09 |
전략 패턴의 실제 사례 (0) | 2020.09.09 |