サーバータグ内でifステートメントまたはtrycatchブロックを使用できるかどうか疑問に思っていますか?すなわち:
'<%= if(grid!=null){((DropDownList)this.grid.FindControl("SRPType")).ClientID} %>'
<% try { %>
<%= (grid != null) ?
((DropDownList)this.grid.FindControl("SRPType")).ClientID : ""
%>
<% }
catch {
... exception handling
}
%>
<%=%>構文を使用する代わりに、<%%>を使用し、Response.Writeを呼び出して出力値を書き込みます。例:
<%
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 : "" )%>