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

前端 未结 2 1039
Happy的楠姐
Happy的楠姐 2021-01-28 02:05

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

相关标签:
2条回答
  • 2021-01-28 02:20

    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);
    
    0 讨论(0)
  • 2021-01-28 02:36

    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")) %>'
    
    0 讨论(0)
提交回复
热议问题