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:
Any suggestion is appreciated.
Thanks
Thomas
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); |
sb.AppendLine(""); |
sb.AppendLine(callbackFunc); |
sb.AppendLine(postbackFunc); |
string initScript = string.Format(initScriptTemplate, sb.ToString()); |
Any suggestion is appreciated.
Thanks
Thomas