Loading Usercontrol if flash player is not installed - Ajax

Last post 05-27-2009 2:02 AM by ngchandran. 0 replies.

Sort Posts:

  • Loading Usercontrol if flash player is not installed - Ajax

    05-27-2009, 2:02 AM
    • Member
      point Member
    • ngchandran
    • Member since 06-14-2007, 2:12 PM
    • Posts 3
    Hi,I am finding difficulties in loading a user control at runtime using Ajax. If Flash player is not installed in the client system then I need to bind the user control in the web page. I tried this by using Ajax call but only my page load event  is invoked when it hit JavaScript line CallServer('getUserControl','') not RaiseCallbackEvent. CallServer function in the JavaScript is not calling RaiseCallBackEvent when it is declared inside the body tag. It works fine if I have JavaScript in the <head> tag, but my scenario is only if flash player is not installed then I should load user control in the respective div tag.  Please find below the line of code written in the code behind file public partial class HomePage : Microsoft.SharePoint.Publishing.PublishingLayoutPage, ICallbackEventHandlerprivate void Page_Load(object sender, System.EventArgs e)

    {

    RegisterClientCallbacks();} private void RegisterClientCallbacks(){string callbackRef = Page.ClientScript.GetCallbackEventReference(this, "arg", "RecieveServerData", "context", true);string script = String.Empty;if (!Page.ClientScript.IsClientScriptBlockRegistered("CallServer")){script = "function CallServer(arg,context) { " + callbackRef + "}";Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", script, true);}} public static string RenderControl(Control control){StringWriter tw = new StringWriter();Html32TextWriter writer = new Html32TextWriter(tw);control.RenderControl(writer); writer.Close();return tw.ToString();}private string _callbackArg;void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument){_callbackArg = eventArgument;} string ICallbackEventHandler.GetCallbackResult(){return RaiseCallbackEvent(_callbackArg);} protected virtual string RaiseCallbackEvent(string eventArgument){string dvhtml = "";if (eventArgument == " getUserControl "){HtmlGenericControl divUCPromotion = new HtmlGenericControl();divUCPromotion.Controls.Add(LoadControl("UserControl.ascx"));dvhtml = RenderControl(divUCPromotion);}return dvhtml;} JavaScript<div id="divtest" runat="server"><script language="JavaScript" type="text/javascript">var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);if(hasRightVersion) {getFlash();  //loading flash component here} else {CallServer('getUserControl','');  //calling server to bind the user control                                 }function RecieveServerData(response,a) {  document.write(response);}</script>  </div> Please help me in resolving this issues. Regards,Jai 
Page 1 of 1 (1 items)