This is a migrated thread and some comments may be shown as answers.

How to disable javascript for RAD Controls

2 Answers 143 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Manoj
Top achievements
Rank 1
Manoj asked on 09 Nov 2010, 10:48 PM
Hi,

We have a requirement to render a page in edit mode and read only mode.

The RAD controls that we are using are custom classes that inherits from Rad control classes. For example we have a class called CSRadComboBox that extends from the class RadComboBox and we use the instances of class CSRadComboBox in all the code for the project.

When a page is rendered in the read-only mode to the users, we override the Render method of the RadComboBox and render an System.Web.UI.WebControls.Label object with the contents in it. I have copy pasted the code used to render in the readonly mode for one of the controls below.
protected override void Render(HtmlTextWriter writer)
{
    if (IsReadOnly)
    {
        Label lblValue = new Label();
        string display = "--";
        if (!string.IsNullOrEmpty(this.SelectedText))
        {
            display = this.SelectedText;
        }
        lblValue.Text = display;
        lblValue.RenderControl(writer);
    }
    else
    {
        base.Render(writer);
    }
}


We have a problem in the readonly pages that there are lot of javascript error that is thrown, "null is null or not an object" and when debugged in visual studio, we could make out that the ajax javascript from the telerik resource is trying to attach events to the labels that has been entered and since it is not able to find the actual control, the javascript error is being thrown.

We need help on how to disable javascript for individual rad controls in the readonly view of the page when actually it is not required at all.

Thanks,
Manoj

Ravishankar
Top achievements
Rank 1
Iron
commented on 08 Aug 2023, 08:44 PM

Were you able to overcome this issue?
Rumen
Telerik team
commented on 09 Aug 2023, 11:21 AM

The suggested approach by Peter is still applicable: EnableEmbeddedScripts="false".
Ravishankar
Top achievements
Rank 1
Iron
commented on 09 Aug 2023, 12:35 PM | edited

Thanks Ruben for responding. EnableEmbeddedScripts="false" method didn't work for me. I added another approach that worked out well for me. Added in the Answer section below
Rumen
Telerik team
commented on 09 Aug 2023, 01:38 PM

Thank you for sharing your solution with the community, Ravishankar! This is much appreciated!

2 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 11 Nov 2010, 03:08 PM
Hello Manoj,

Please, try setting EnableEmbeddedScripts="false" for the controls that you need to disable loading their javascript files.


All the best,
Peter
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ravishankar
Top achievements
Rank 1
Iron
answered on 09 Aug 2023, 12:43 PM | edited on 09 Aug 2023, 12:44 PM

For me, I had to allow base.Render(writer); so that the render operation get completed successfully other wise if any posback happens then I get javascript errors. I dynamically hide the control in Render method so that it will not get displayed in the page for the user but embedded javascript methods still finds the control to complete all it's necessary scripts.

 

protected override void Render(HtmlTextWriter writer)
{
    if (IsReadOnly)
    {
        this.Attributes.Add("style", "display:none");
        string display = "--";
        if (!string.IsNullOrEmpty(this.SelectedText))
        {
            display = this.SelectedText;
        }
        writer.Write(display);
    }

     base.Render(writer);
}

 

If needed you can still use label control to render instead of using writer.Write method but in my case, I tried using writer method directly (don't want to introduce a new label control into the mix)


Tags
Ajax
Asked by
Manoj
Top achievements
Rank 1
Answers by
Peter
Telerik team
Ravishankar
Top achievements
Rank 1
Iron
Share this question
or