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

Trying to create client component on partial postback

1 Answer 57 Views
This is a migrated thread and some comments may be shown as answers.
Thomas Mittag
Top achievements
Rank 1
Thomas Mittag asked on 23 Feb 2009, 05:05 PM
I have a custom control which inserts java script into an Ajax panel. The java script is creating a client component which can be accessed using the $find function.  This works well when the control is created during a full postback.  Unfortunately I am having a scenario where the control is created as part of a User Control that is used as the Edit Form of a RadGrid control.
The RadGrid is inside an RadAjaxPanel, it appears, that the javascript code, that is usually executed on Page load is not executed, and the client component is not known.  The code for the script block I have gotten from another Telerik thread suggesting to putting the code inside the Ajax Panel to allow for partial postbacks of the custom control itself. Here is the code:

                //init part for control generation... 
                string initScriptTemplate = "<script type='text/javascript'>{0}</script>"
                string postBackEvent = Page.ClientScript.GetPostBackEventReference(this, "arg"); 
                postBackEventpostBackEvent = postBackEvent.Replace("'arg'", "arg"); 
                string callBackEvent = Page.ClientScript.GetCallbackEventReference(this, "arg", "CallbackResult", "context", false); 
                string callbackFunc = string.Format("function {0}_doCallback(arg, context) {{ {1}; }}", this.ClientID, callBackEvent); 
                string postbackFunc = string.Format("function {0}_doPostback(arg) {{ {1}; }}", this.ClientID, postBackEvent); 
                string postbackCall = string.Format("{0}_doPostback", this.ClientID); 
                string callbackCall = string.Format("{0}_doCallback", this.ClientID); 
                //string initCodeTemplate = "var {1} = new REACH.ModalPopupControl(\"{0}\",\"{1}\",{2},{3},\"{4}\")"; 
                string initCodeTemplate = "var app = Sys.Application; app.add_init(function() {{ $create( REACH.ModalPopupControl, {{id:\"{0}\", _radwindowId:\"{1}\", _postbackFunction: {2}, _callbackFunction: {3} }}, null, null ); }});"; 
                object[] items = { this.CallerID, this.RadWindowID, postbackCall, callbackCall }; 
                StringBuilder sb = new StringBuilder(); 
                sb.AppendFormat(initCodeTemplate, items); 
                string initScript = string.Format(initScriptTemplate, sb.ToString()); 

Any suggestion is appreciated.


1 Answer, 1 is accepted

Sort by
Iana Tsolova
Telerik team
answered on 25 Feb 2009, 09:05 AM
Hello Thomas,

I went through your code and it looks fine to me. However, based on the given information, I assume that the client script was not able to register properly and that is why you end up with the 'null' exception.
Therefore I suggest that you send me a runnable code so I could debug it locally and try finding a resolution for you.

Best wishes,
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Asked by
Thomas Mittag
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question