0

I need to create a functinality in which I have to create the Html file in which is written in c# like this

string strHTMLGrid = "";
strHTMLGrid = strHTMLGrid + "<body id='body1'  onload='OpenCube()'>";
strHTMLGrid = strHTMLGrid + "<h1>" + sHeading + "</h1>";
strHTMLGrid = strHTMLGrid + "<div id='EVObject_xml' style='margin: 0px; position: absolute; top: 12px; left: 0px; bottom: 0px; right: 0px; '>";
strHTMLGrid = strHTMLGrid + "<object name='EVObject' width='100%' height='100%' id='EVObject' codebase='" + sUrlHtml + "' lang='en-US' classid='clsid:80AC1200-0BBE-499A-A9E9-5F334DBC8E89'>";
strHTMLGrid = strHTMLGrid + "<param name='Server' value='" + sServername1 + "'>";
strHTMLGrid = strHTMLGrid + "<param name='Server' value='" + sTheme1 + "'>";
strHTMLGrid = strHTMLGrid + "<param name='Server' value='" + sHeading + "'>";
strHTMLGrid = strHTMLGrid + "</object>";
strHTMLGrid = strHTMLGrid + "</div>";
strHTMLGrid = strHTMLGrid + "<div id='ribbon'>";
strHTMLGrid = strHTMLGrid + "<div id='backstage - container'> </div>";
strHTMLGrid = strHTMLGrid + "</div>";
strHTMLGrid = strHTMLGrid + "</body>";

In this I have declared a function on load a function named opencube() and I need to call it in c# on the load of the body

    string jScriptValidator;
    jScriptValidator = "<script> function OpenCube()" + "\n";
    jScriptValidator = "<script> { \n";
    jScriptValidator += "EVObject.Enable(UIAuthorisationType.UIAuthorisationToolbar, true); \n ";
    jScriptValidator += "EVObject.Enable(UIAuthorisationType.UIAuthorisationTabBar, true); \n";
    jScriptValidator += "EVObject.TabBarPosition = TabBarPositionType.TabBarPositionBottom; \n";
    jScriptValidator += "EVObject.Allow(ActionAuthorisationType.UIAuthorisationToolbarText, false); \n";
    jScriptValidator += "EVObject.ToolBar.LargeButtons = false; \n";
    jScriptValidator += "EVObject.Enable(UIAuthorisationType.UIAuthorisationLocalViews, false)\n";
    jScriptValidator += "EVObject.Allow(ActionAuthorisationType.ActionAuthorisationDataEntry, false);\n";
    jScriptValidator += "EVObject.Allow(ActionAuthorisationType.ActionAuthorisationSaveView, true);\n";
    jScriptValidator += "EVObject.Allow(ActionAuthorisationType.ActionAuthorisationExport, true);\n";
    jScriptValidator += "EVObject.Allow(ActionAuthorisationType.ActionAuthorisationExportToExcel, true);\n";
    jScriptValidator += "EVObject.ViewLocations = 'General =/';\n";
    jScriptValidator += "EVObject.object.attachEvent('NeedDataSourceCredentials', DataSourceCredentials); \n";
    jScriptValidator += "EVObject.Enable(EVObject.object.attachEvent('NeedServerCredentials', ServerCredentials);\n";
    jScriptValidator += "EVObject.Views.Open('/ Outdb / mis');\n";
    jScriptValidator += " LeaveBackstage(); \n";
    jScriptValidator += "ExpandRibbons(false); \n";
    jScriptValidator += "ShowBackstage(false); \n";
    jScriptValidator += " } </script>";

Now how to connect both of them i don't know.

Basant Gera
  • 103
  • 3
  • 16
  • FYI [Multiline String Literal in C#](http://stackoverflow.com/questions/1100260/multiline-string-literal-in-c-sharp) – Alex K. Aug 03 '16 at 13:15
  • What do you mean by **connect both of them**? Do you want to insert the script in the HTML? – sachin Aug 03 '16 at 13:15
  • I need to Make a Html File dynamically in which on a click of button html file genrated with that some parameters are their given by client..to open the things in javascript. – Basant Gera Aug 03 '16 at 15:16
  • Yes I need to insert the script so that on the load of body the javascript function will get called in C# – Basant Gera Aug 03 '16 at 15:16

1 Answers1

0

You probably need to insert the string containing the script inside the html string. In order to do that first declare the script string:

I believe you hace declared the opening of the script tag twice, and maybe you also need to add a document.ready function in order for the script to execute correctly once your html loads.

   string jScriptValidator;
    jScriptValidator = "<script> function OpenCube()" + "\n";
    jScriptValidator = "<script> { \n";
    jScriptValidator += "EVObject.Enable(UIAuthorisationType.UIAuthorisationToolbar, true); \n ";
    jScriptValidator += "EVObject.Enable(UIAuthorisationType.UIAuthorisationTabBar, true); \n";
    jScriptValidator += "EVObject.TabBarPosition = TabBarPositionType.TabBarPositionBottom; \n";
    jScriptValidator += "EVObject.Allow(ActionAuthorisationType.UIAuthorisationToolbarText, false); \n";
    jScriptValidator += "EVObject.ToolBar.LargeButtons = false; \n";
    jScriptValidator += "EVObject.Enable(UIAuthorisationType.UIAuthorisationLocalViews, false)\n";
    jScriptValidator += "EVObject.Allow(ActionAuthorisationType.ActionAuthorisationDataEntry, false);\n";
    jScriptValidator += "EVObject.Allow(ActionAuthorisationType.ActionAuthorisationSaveView, true);\n";
    jScriptValidator += "EVObject.Allow(ActionAuthorisationType.ActionAuthorisationExport, true);\n";
    jScriptValidator += "EVObject.Allow(ActionAuthorisationType.ActionAuthorisationExportToExcel, true);\n";
    jScriptValidator += "EVObject.ViewLocations = 'General =/';\n";
    jScriptValidator += "EVObject.object.attachEvent('NeedDataSourceCredentials', DataSourceCredentials); \n";
    jScriptValidator += "EVObject.Enable(EVObject.object.attachEvent('NeedServerCredentials', ServerCredentials);\n";
    jScriptValidator += "EVObject.Views.Open('/ Outdb / mis');\n";
    jScriptValidator += " LeaveBackstage(); \n";
    jScriptValidator += "ExpandRibbons(false); \n";
    jScriptValidator += "ShowBackstage(false); \n";
    jScriptValidator += " } </script>";

Once you have your script tag you can insert it inside the html string. Check out the line before the body tag closes

string strHTMLGrid = "";
strHTMLGrid = strHTMLGrid + "<body id='body1'  onload='OpenCube()'>";
strHTMLGrid = strHTMLGrid + "<h1>" + sHeading + "</h1>";
strHTMLGrid = strHTMLGrid + "<div id='EVObject_xml' style='margin: 0px; position: absolute; top: 12px; left: 0px; bottom: 0px; right: 0px; '>";
strHTMLGrid = strHTMLGrid + "<object name='EVObject' width='100%' height='100%' id='EVObject' codebase='" + sUrlHtml + "' lang='en-US' classid='clsid:80AC1200-0BBE-499A-A9E9-5F334DBC8E89'>";
strHTMLGrid = strHTMLGrid + "<param name='Server' value='" + sServername1 + "'>";
strHTMLGrid = strHTMLGrid + "<param name='Server' value='" + sTheme1 + "'>";
strHTMLGrid = strHTMLGrid + "<param name='Server' value='" + sHeading + "'>";
strHTMLGrid = strHTMLGrid + "</object>";
strHTMLGrid = strHTMLGrid + "</div>";
strHTMLGrid = strHTMLGrid + "<div id='ribbon'>";
strHTMLGrid = strHTMLGrid + "<div id='backstage - container'> </div>";
strHTMLGrid = strHTMLGrid + "</div>";
strHTMLGrid = strHTMLGrid + jScriptValidator;
strHTMLGrid = strHTMLGrid + "</body>";

Is this what you wanted??

Agustin Castro
  • 281
  • 3
  • 11
  • I dnt know how on load of body in html (c#) how my javascript (c#) will get called and html will get genrated...right now i am when i press f5 it comes to strHTMLGrid but dont call OpenCube() in javascript in C# – Basant Gera Aug 03 '16 at 15:19
  • Ok, remember javascript is the language of the browser and C# runs in the server. So you need to separate code executed in the server from the one executed in the browser. Maybe you can solve this by loading the content asynchronously via ajax. Is that a possible scenario for your problem? – Agustin Castro Aug 03 '16 at 15:42
  • No Austin, Its not possible I need to create the html file in seerver side and thats why javascript too written der only on server side code in form of C# and than i need to pass the parameters in form of ' Parameter name' – Basant Gera Aug 03 '16 at 15:55
  • maybe a possible solution is to get the object EVObject by id inside your script instead of passing it as a parameter. You can do this by adding the line var EVObject = document.getElementById("EVObject"); in the begining of your script string, and then handling it inside the function – Agustin Castro Aug 03 '16 at 16:05