开发者

<%= %> embedded in Javascript IF Condition

开发者 https://www.devze.com 2023-01-09 21:04 出处:网络
In aspx page: if (<%= Not Me.ThisVi开发者_开发问答sa.PassportExpirationDate.IsNull %>){ Returns error:

In aspx page:

if (<%= Not Me.ThisVi开发者_开发问答sa.PassportExpirationDate.IsNull %>){   

Returns error:

Microsoft JScript runtime error: 'True' is undefined

I tried this:

if ("<%= Me.ThisVisa.PassportExpirationDate.IsNull.ToString %>" != "True"){   

..but I get a compile time error:

Error   5   Option Strict On disallows implicit conversions from 'String' to 'Long'

Help!


Consider moving the logic into the server script. Doing so will reduce how much JavaScript you emit onto the page.

<% If Not Me.ThisVisa.PassportExpirationDate.IsNull Then %>

// JavaScript Goodness

<% End If %>


What about:

if (<%= (Not Me.ThisVisa.PassportExpirationDate.IsNull).ToString().ToLower() %>){  

This will evaluate the Boolean condition and convert it to a string, but you should lower-case it so it looks like JavaScript syntax when it's rendered.


Get rid of the extra spaces. Change to:

if ("<%=Me.ThisVisa.PassportExpirationDate.IsNull.ToString%>" != "True"){


You are missing the parenthesis for the ToString() method.

update: sry, my bad

0

精彩评论

暂无评论...
验证码 换一张
取 消