Rajaram Shelar
Rajaram Shelar

Reputation: 7897

The server tag is not well formed. When passing parameters to javascript function

Hi have always trouble with calling JavaScript function with parameters values as values bonded to the gridview. I follow SO Thread But can not used for passing this parameter . Below is the statement that I used in my aspx page.

onblur="return ValidateText(this,'<%# Eval("vehicleId") %>')"

But this gives me parsing error The server tag is not well formed. How should I call this function in design only(not from code behind).

Upvotes: 0

Views: 1663

Answers (2)

Harsh Baid
Harsh Baid

Reputation: 7249

I think the problem is the outer-most double quotes ", change that to single quotes '.

onblur='return ValidateText(this,'<%# Eval("vehicleId") %>')'

UPDATE

Try using string.Format() as mentioned in the SO question your are refering..

onblur='<%# System.String.Format("return ValidateText(this, \"{0}\")", Eval("vehicleId")) %>'

Upvotes: 1

codingbiz
codingbiz

Reputation: 26406

This works, but seems an HACK because I removed the enclosing quotes (anti-XHtml)

 onblur=<%# String.Format("return ValidateText(this, '{0}')", Eval("VehicleID")) %>

The problem is having " "" " or ' '' ' as part of the string.

This is better done (I wish it is easier in markup), in code-behind, e.g. RowDataBound or ItemDataBound

 control.Attributes["onblur"] = String.Format("return ValidateText(this, '{0}')", rowValue);

Upvotes: 6

Related Questions