C# 如何在服务器标记内使用if或try catch块
我想知道是否可以在服务器标记中使用if语句或try-catch块?即:C# 如何在服务器标记内使用if或try catch块,c#,asp.net,C#,Asp.net,我想知道是否可以在服务器标记中使用if语句或try-catch块?即: '<%= if(grid!=null){((DropDownList)this.grid.FindControl("SRPType")).ClientID} %>' “” 使用和调用写入输出值,而不是使用语法,例如: <% if(grid!=null) { try { var myList=(DropDownList)this.grid
'<%= if(grid!=null){((DropDownList)this.grid.FindControl("SRPType")).ClientID} %>'
“”
使用和调用写入输出值,而不是使用语法,例如:
<%
if(grid!=null)
{
try
{
var myList=(DropDownList)this.grid.FindControl("SRPType");
if (myList!=null)
Response.Write( myList.ClientID);
else
Response.Write("Where's my listbox?");
}
catch(Exception exc)
{
//Report error, maybe warn user
}
}
%>
使用和调用写入输出值,而不是使用语法,例如:
<%
if(grid!=null)
{
try
{
var myList=(DropDownList)this.grid.FindControl("SRPType");
if (myList!=null)
Response.Write( myList.ClientID);
else
Response.Write("Where's my listbox?");
}
catch(Exception exc)
{
//Report error, maybe warn user
}
}
%>
不知道异常,但您可以始终使用内联if语句
<%=(grid != null ? ((DropDownList)this.grid.FindControl("SRPType")).ClientID : "" )%>
不知道异常,但您可以始终使用内联if语句
<%=(grid != null ? ((DropDownList)this.grid.FindControl("SRPType")).ClientID : "" )%>
不能。它在javascript中的一个标记中。那么请提供相关的块,而不仅仅是它的一部分。它在javascript中的一个标记中。那么请提供相关的块,而不仅仅是它的一部分。您提到的这是在javascript中的一个块中。请提供您提到的整个块,这是javascript中的一个块。请提供全部信息,谢谢。非常感谢,谢谢。我非常感激。