C# 后台生成javascript

            <td class="TDTitle" style="border: none">
                <asp:Button CssClass="buttonMaterials fontSizeSmaller" ID="btnViewMaterials" runat="server"
                    Text="申請資材" Visible="false" OnClientClick="viewMaterials();return false;"/>
            </td>


    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        bool isHistory = false;
        if (Session[SESSION_KEY_IS_HISTORY] != null)
        {
            isHistory = (bool)Session[SESSION_KEY_IS_HISTORY];
            Session[SESSION_KEY_IS_HISTORY] = false;
        }

        this.ViewMenuButton(new StatusManager(hdnStatusNo.Value), isHistory);
        this.ViewControl(new StatusManager(hdnStatusNo.Value), isHistory);

        this.GenerateDrugAndProdJavaScript();
        this.GenerateApplicantJavaScript();
        this.GenerateSuperiorJavaScript();
        this.GenerateOldApplicationJavaScript();
        this.GenerateViewMaterials(hdnApplicationNo.Value);
        this.GenerateReportJavaScript();

        this.SetReadOnlyValue();
    }


    /// <summary>
    /// 申請資材用のスクリプトを生成する
    /// </summary>
    protected void GenerateViewMaterials(string applicationNo)
    {
        string materialsPath = ConfigurationManager.AppSettings["MaterialsReferencePath"];

        StringBuilder script = new StringBuilder();
        script.Append("<script type=text/javascript>");
        script.Append("function viewMaterials(){");
        script.Append("location.href = '");
        script.Append(materialsPath);
        script.Append("\\");
        script.Append(applicationNo);
        script.Append("';");
        script.Append("}");
        script.Append("</script>");
        Page.ClientScript.RegisterClientScriptBlock(typeof(string), "ViewMaterialsScript", script.ToString());
    }
原文地址:https://www.cnblogs.com/haiy/p/4060061.html