我遇到以下代码块的问题:
Dim scriptHere As System.Web.UI.HtmlControls.HtmlGenericControl = control.Page.FindControl("scriptHere")
Dim controlID As String = ""
Dim disabled As String = IIf(isDisabled, "true", "false")
If TypeOf (control) Is ASPxEditBase Then
controlID = control.ID
End If
Try
control.ReadOnly = isDisabled
Dim script As String = ""
script &= "<script type=""text/javascript"">" & vbCrLf
script &= "// <![CDATA[" & vbCrLf
script &= "try {" & vbCrLf
script &= "$('#<%= " + controlID + ".ClientID %>').attr('disabled', " + disabled + ");" & vbCrLf
If selectedIndex <> -1 Then
control.SelectedIndex = selectedIndex
script &= "" + controlID + ".SetValue(" + selectedIndex.ToString() + ");" & vbCrLf
End If
script &= "} catch (e) { " & IIf(showErrors, "alert(e.message);", ";") & " }" & vbCrLf
script &= "// ]]> " & vbCrLf
script &= "</script>" & vbCrLf
scriptHere.InnerHtml &= script
Catch ex As Exception
Console.Out.WriteLine(ex.ToString())
End Try
问题是,它引发了我的异常。 更确切地说,它只是说“未定义”而没有别的。 我认为问题在于这一行:
script &= "$('#<%= " + controlID + ".ClientID %>').attr('disabled', " + disabled + ");" & vbCrLf
此外,由于这是一个jQuery命令,我可以假设异常是由“$”引起的。
额外信息:
jQuery(document).ready(function ()
{/.../});
这就是现在。 提前谢谢。
答案 0 :(得分:1)
好的,看看这是否有效 -
script &= "$('#" + controlID.ClientID + "').attr('disabled', " + disabled + ");" & vbCrLf
看起来内联VB没有提取正确的客户端ID,但是你已经在服务器端获得了它,所以你应该能够一次性构建整个脚本字符串。