I have a problem with the following code block:
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
The problem is, that it throws me an Exception. To be more precise it just says "Undefined" and nothing else. I figured that the problem lies within this line:
script &= "$('#<%= " + controlID + ".ClientID %>').attr('disabled', " + disabled + ");" & vbCrLf
Furthermore, with this being a jQuery command i can assume that the Exception is caused by the "$".
Extra Info:
- I have the required jQuery library linked.
- I have tried adding the
jQuery(document).ready(function () {/.../}); - I have tried executing the same script using ScriptManager.
- I have tried calling this sub on page_load instead of an earlier phase of page rendering
- I have also tried linking the jQuery library within this script block.
That's all for now. Thanks in advance.
<script type="text/javascript"> // <![CDATA[ jQuery(document).ready(function(){ try { $('#<%= cbRelation.ClientID %>').attr('disabled', true); cbRelation.SetValue(1); } catch (e) { alert(e.message); } }); // ]]> </script>