0

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:

  1. I have the required jQuery library linked.
  2. I have tried adding the jQuery(document).ready(function () {/.../});
  3. I have tried executing the same script using ScriptManager.
  4. I have tried calling this sub on page_load instead of an earlier phase of page rendering
  5. I have also tried linking the jQuery library within this script block.

That's all for now. Thanks in advance.

2
  • Can you see the javascript being rendered onto the page (via View Page Source)? Is that being written as expected? Commented Jul 30, 2013 at 14:02
  • Yup, here it is <script type="text/javascript"> // <![CDATA[ jQuery(document).ready(function(){ try { $('#<%= cbRelation.ClientID %>').attr('disabled', true); cbRelation.SetValue(1); } catch (e) { alert(e.message); } }); // ]]> </script> Commented Jul 30, 2013 at 14:10

1 Answer 1

1

Ok, see if this would work -

script &= "$('#" + controlID.ClientID + "').attr('disabled', " + disabled + ");" & vbCrLf

It looks like the inline VB isn't pulling out the correct client id, but you've already got it server-side, so you should be able to build the entire script string up in one go.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.