嗨,在调用 JavaScript 函数时总是遇到麻烦,参数值作为绑定到 gridview 的值。我遵循SO Thread但不能用于传递this参数。下面是我在我的 aspx 页面中使用的语句。
onblur="return ValidateText(this,'<%# Eval("vehicleId") %>')"
Run Code Online (Sandbox Code Playgroud)
但这给了我解析错误The server tag is not well formed.我应该如何仅在设计中调用此函数(而不是从后面的代码中调用)。
这有效,但似乎是 HACK,因为我删除了封闭引号(反 XHtml)
onblur=<%# String.Format("return ValidateText(this, '{0}')", Eval("VehicleID")) %>
Run Code Online (Sandbox Code Playgroud)
问题是具有" "" "或' '' '作为字符串的一部分。
这样做更好(我希望在标记中更容易),在代码隐藏中,例如 RowDataBound 或 ItemDataBound
control.Attributes["onblur"] = String.Format("return ValidateText(this, '{0}')", rowValue);
Run Code Online (Sandbox Code Playgroud)