我已在PlaceholderMain下的应用程序页面中添加了我的JavaScript
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript" lang="javascript">
function change() {
var Email = document.getElementById('ctl00_PlaceHolderMain_ctl00_FBACreateUserWizard_CreateUserStepContainer_Email');
var UserName = document.getElementById('ctl00_PlaceHolderMain_ctl00_FBACreateUserWizard_CreateUserStepContainer_UserName');
UserName.value = Email.value;
}
</script>
使用字符串生成器,我将此代码添加到applicationpage.cs
protected void RenderContents(HtmlTextWriter writer)
{
System.Text.StringBuilder sb2 = new System.Text.StringBuilder();
sb2.AppendLine(@"<script language='javascript'>");
sb2.AppendLine(@"function change(){");
sb2.AppendLine(@"var Email = document.getElementById('ctl00_PlaceHolderMain_ctl00_FBACreateUserWizard_CreateUserStepContainer_Email');");
sb2.AppendLine(@"var UserName = document.getElementById('ctl00_PlaceHolderMain_ctl00_FBACreateUserWizard_CreateUserStepContainer_UserName');");
sb2.AppendLine(@"UserName.value=Email.value;");
sb2.AppendLine(@" }");
sb2.AppendLine(@"</script>");
if (!Page.ClientScript.IsStartupScriptRegistered("JSScript"))
{
Page.ClientScript.RegisterStartupScript(this.GetType(),"JSScript", sb2.ToString());
}
}
通过浏览器调试检查应用程序页面时,看不到添加到该页面的JavaScript。
我能知道如何将其添加到应用程序页面吗?
以前,我在SharePoint页面中测试了此代码,当我尝试将其添加到应用程序页面时,JavaScript并未呈现到页面中,因此现在可以正常工作。