Want to Dynamically Create a RadWindow in External Server-side Code

2 posts, 0 answers
  1. Robert
    Robert avatar
    253 posts
    Member since:
    Aug 2007

    Posted 29 Jan 2012 Link to this post

    In my website project I have a top-level file called "Common.cs" that is shared by all the forms in the project.  It contains common code that needs to access the Website UI.  I'd like to dynamically create a dialog box that will allow the user to enter additional comments in the event of an error.

    I've written some code that is not crashing but yet no RadWindow is appearing.  Here's the crux of what I have so far:

        public static void ShowErrorDialog(string msg, Constants.ErrorCode category, string location, Control parent)<br>    {<br>      RadWindow rw = new RadWindow();<br>      rw.ID = "rwErrorHandling";<br>      rw.VisibleOnPageLoad = true;<br>      rw.CssClass = "errorDialog2";<br>      rw.Behaviors = WindowBehaviors.Move;<br>      rw.EnableShadow = true;<br>      rw.VisibleStatusbar = false;<br>      rw.VisibleTitlebar = true;<br>      rw.Visible = true;<br>      //rw.AutoSize = true;<br>      rw.Width = 300;<br>      rw.Height = 200;<br>      rw.Modal = true;<br>      <br>      // Much more code here to create the contents of the dialog box<br>      <br>      parent.Page.Controls[0].FindControl("form1").Controls.Add(rw);<br>    }

    And here's a sample call to the method:

      Website.Common.ShowErrorDialog("Test message", Constants.ErrorCode.UnexpectedRecordCount, "buttonTest", Page);

    Hoping someone can tell me why the RadWindow is not appearing,

    Robert

    P.S. In case it helps, here's displayed info from jQuery when I'm stepping through client-side code:

    ? $('div[id$=_rwNewMuckpile]')[0].id
    "ctl00_ContentPlaceHolder1_Mucking_rwNewMuckpile"
        endsWith: function String$endsWith(suffix) {
        /// <summary locid="M:J#String.endsWith" />
        /// <param name="suffix" type="String"></param>
        /// <returns type="Boolean"></returns>
        var e = Function._validateParams(arguments, [
            {name: "suffix"
        startsWith: function String$startsWith(prefix) {
        /// <summary locid="M:J#String.startsWith" />
        /// <param name="prefix" type="String"></param>
        /// <returns type="Boolean"></returns>
        var e = Function._validateParams(arguments, [
            {name: "pre
        trim: function String$trim() {
        /// <summary locid="M:J#String.trim" />
        /// <returns type="String"></returns>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this.replace(/^\s+|\s+$/g, '');
    }
        trimEnd: function String$trimEnd() {
        /// <summary locid="M:J#String.trimEnd" />
        /// <returns type="String"></returns>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this.replace(/\s+$/, '');
    }
        trimStart: function String$trimStart() {
        /// <summary locid="M:J#String.trimStart" />
        /// <returns type="String"></returns>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this.replace(/^\s+/, '');

    So something "appears" to be there but if I make this call: $find($('div[id$=_rwNewMuckpile]')[0].id)
    then I get 'null'.  :-(
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4526 posts

    Posted 31 Jan 2012 Link to this post

    Hello Robert,

    Since you are creating an entirely new control you need to properly add it to the page. When you invoke the method you pass Page as a parameter, so I believe it is possbile that in your project that the control hierarchy is not correct, you may need to do parent.FindControl("form1").Controls.Add(rw); instead. Please debug your code and see if there is some server error at this poing. Please also make sure you are not calling it from an AJAX request, i.e. that the form is updated so taht the RadWindow is sent to it. What you can also try is to add this RadWindow to the parent element that invoked the method, not to the page, so that it is more probable that it will be included in the AJAX response.


    Kind regards,
    Marin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top