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

Fetching user control with Rad Controls using web service

6 Answers 185 Views
XmlHttpPanel
This is a migrated thread and some comments may be shown as answers.
Abhay Jain
Top achievements
Rank 1
Abhay Jain asked on 03 Feb 2010, 06:57 PM
Hi.

I have a user control which has a repeater. Each row of the repeater has three columns containing a control each

1st column - ASP label control
2nd column - Rad Combo Box
3rd column - Rad Text Box

This user control has a public property that accepts the data to be bound to the repeater control.

I want to achieve the following.

On the main web page, on a click of button, using a web service i want to get the HTML content of the above user control.

In web service, I create an instance of Page, dynamically load the above user control, add it to the page, get the HTML of page
and send that HTML as a string to the requesting web page.

The above thing works if I don't have Rad Controls in the user control. If I use generic HTML controls or asp controls (that don't require scriptmanager) it works perfectly fine. But there are Rad Controls, when I try to get the HTML of the page by calling RenderControl I get an error saying 'ScriptManager' needs to be present.

Is there an alternate way to circumvent the problem?

Thanks.

6 Answers, 1 is accepted

Sort by
0
Pero
Telerik team
answered on 08 Feb 2010, 03:49 PM
Hi Abhay,

Please try the following:

  1. Add a ScriptManager to the Page where you dynamically add the UserControl;
  2. Set the RegisterWithScriptManager property of all RadControls (i.e. to the RadComboBox and the RadTextBox) within the UserControl to false.


Best wishes,
Pero
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Abhay Jain
Top achievements
Rank 1
answered on 09 Feb 2010, 05:56 AM
Thanks Pero, really appreciate to lead me to the right direction.

In fact, after seeing the reply I actually thought that I have got the solution.

But alas! I couldn't even find this property for RadComboBox. *** RegisterWithScriptManager ***

Does it have anything to do with the version of RadControls that I am using? **  RadControls for ASP .NET AJAX Q3 2008  **

~Abhay
0
Pero
Telerik team
answered on 10 Feb 2010, 12:30 PM
Hi Abhay,

First of all please clarify which version of the RadControls for ASP.NET AJAX you are using? RadXmlHttpPanel was introduced for the first time in Q2 2009 - 2009.2 701, so I guess you are using the latest together with an earlier version of the RadControls for ASP.NET AJAX. The RegisterWithScriptManager property is not available in Q3 2008.

Please make sure that you are using the latest version of the controls and let us know if the problem persists.


Kind regards,
Pero
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Abhay Jain
Top achievements
Rank 1
answered on 11 Feb 2010, 04:11 AM
Hi Pero,

Thanks for the reply.

I am using RadControls for ASP .NET AJAX Q3 2008. (I did mention that, but not very explicitly :) This version of Telerik controls doesn't support RadXmlHttpPanel. I started this thread under RadXmlHttpPanel because we want the exactly same functionality.

I guess, RegisterWithScriptManager isn't supported by the version that I am using.

It would be great, if you tell me any alternative then upgrading to the latest Telerik control because latter is, at this point, little difficult.

Regards,
~Abhay

0
Accepted
Pero
Telerik team
answered on 16 Feb 2010, 12:48 PM
Hello Abhay,

You can create a page dynamically and add System.Web.UI.HtmlControls.HtmlForm. To this form you should add a ScriptManager and the UserControl containing the RadControls. Then output the html of the page and return only the html content of the UserControl. This HTML contains the client scripts (in a <script> tags) loaded by the RadControls. The client scripts are not evaluated and they need to be evaluated manually by explicitly calling window.eval() method or $telerik.evalScripts(element) where element is the parent HTML element containing the scripts to be evaluated.

The following source code creates a Page dynamically:

public partial class Test : System.Web.UI.Page
{
     
}
 
public class ViewManager
{
    public static string RenderView(string path)
    {
        return RenderView(path, null);
    }
 
    public static string RenderView(string path, object data)
    {
        Test pageHolder = new Test();
 
        HtmlForm tempForm = new HtmlForm();
        tempForm.ID = "TempForm";
 
 
        pageHolder.Controls.Add(tempForm);
 
        UserControl viewControl = (UserControl)pageHolder.LoadControl(path);
        viewControl.ID = Guid.NewGuid().ToString();
 
        if (data != null)
        {
            Type viewControlType = viewControl.GetType();
            FieldInfo field = viewControlType.GetField("Data");
 
            if (field != null)
            {
                field.SetValue(viewControl, data);
            }
            else
            {
                throw new Exception("View file: " + path + " does not have a public Data property");
            }
        }
 
 
        tempForm.Controls.Add(new ScriptManager());
        tempForm.Controls.Add(viewControl);
 
 
        StringWriter output = new StringWriter();
        HttpContext.Current.Server.Execute(pageHolder, output, false);
 
        string result = output.ToString();
 
        int endFormIndex = result.IndexOf("<div id=\"content\">");
        result = result.Substring(endFormIndex);
        int endFormTagIndex = result.IndexOf("</form");
        result = result.Substring(0, endFormTagIndex - 1);
 
        return result;
    }
}

For your convenience I have also attached the source code of a sample project that loads UserControl containing other RadControls into a ToolTip using WebService.


Best wishes,
Pero
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
Abhay Jain
Top achievements
Rank 1
answered on 04 Jun 2010, 04:46 PM
First of all 'thanks a tonne' for taking out time and for putting in so much effort to elucidate your approach with a working example. I can't be more grateful to you.

And I am sorry for replying so late. Actually with tight deadline, I had to implement the user control with basic HTML elements and using ASP .NET AJAX control toolkit client library (which was no doubt a hard work).

I saw your reply to this thread today and was amazed. I have learned a new nice way of handling the conundrum that I was posed with.

Telerik Support ROCKS!


Tags
XmlHttpPanel
Asked by
Abhay Jain
Top achievements
Rank 1
Answers by
Pero
Telerik team
Abhay Jain
Top achievements
Rank 1
Share this question
or