2016-08-03 105 views
0

我要調用從代碼behind.I事情我能夠從後面的代碼調用的HTML這樣的:如何在後臺代碼中編寫c#中的JavaScript函數?

它看起來像這樣

<h1>cubus outperform EV Analytics</h1> 

<div style="margin:0px; position:absolute; top:12px; left:0px; bottom:0px; right:0px;" id="EVObject_xml"> 
     <object id="EVObject" name="EVObject" lang="en-US" 
      width="100%" height="100%" CodeBase="http://kl12ACUC/EVServer/Client/Ctrl.cab#version=11,0,0,0" 
      ClassId="clsid:80AC1200-0BBE-499A-A9E9-5F334DBC8E89"> 
       <param Name="Server" Value="kl12ACUC" /> 
       <param Name="EnableTabBar" Value="True" /> 
       <param Name="Theme" Value="Ribbon" /> 
     </object> 
    </div> 
    <div id="ribbon" /> 
    <div id="backstage-container" /> 

,現在它看起來像這樣的代碼

背後
string strHTMLGrid = ""; 
      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>"; 

現在我需要調用的這個網站document.The代碼的身體負荷的JavaScript功能我也有我看起來像這樣

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

       } 

1)問題1 ====現在如何在C#中調用JavaScript函數。
2)問題2 =====如何調用Javascript函數,我寫了html文檔的正文的負載。

回答

2

您應該使用的RegisterStartupScript

private void Page_Load(object sender, System.EventArgs e) 
{ 
    string jScriptValidator; 
    jScriptValidator="<script> function ReqFieldValidator()" + 
       " { if (document.forms[0].txtField.value == '') \n"; 
    jScriptValidator+="{ alert('TextBox cannot be empty') \n "; 
    jScriptValidator+="return false; \n"; 
    jScriptValidator+="} \n"; 
    jScriptValidator+=" return true \n"; 
    jScriptValidator+=" } </script>"; 
    Page.RegisterStartupScript("regJSval",jScriptValidator); 
    btnSubmit.Attributes.Add("onclick","return ReqFieldValidator()"); 
} 

欲瞭解更多您可以參考這個網頁: http://www.codeproject.com/Articles/11098/Use-Call-RegisterStartUpScript-RegisterClientScrip

0

當我從面試官的Visual Studio 2013之前聽說過,人有這個問題,他們想調用JavaScript在代碼後面的文件。以下是使用runat =「server」標籤的方式之一。

<script runat="server"> 
//your java script code 
</script> 

上面的代碼將客戶端後,即會在服務器端

+0

感謝名單中執行鍼對建議叫....哈米德我有辦法做到這一點......謝謝 –

相關問題