首页 > 其他 > 详细

PlaceHolder控件的使用

时间:2016-04-10 20:55:16      阅读:276      评论:0      收藏:0      [点我收藏+]

一、简介

  PlaceHolder为asp.net服务器控件用于为代码添加的控件预留空间,下面将介绍下其实际的应用场景。  

<asp:PlaceHolder ID="PH" runat="server"></asp:PlaceHolder>

二、实际应用场景

1、动态添加js

cs文件:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;

namespace UI
{
    public partial class Test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {            
            Literal Li = new Literal();
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("<script src=\"Scripts/Test.js\"></script>");
            Li.Text = sb.ToString();           
            PH.Controls.Add(Li);           

        }
    }
}

Html文件:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="UI.Test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>    
    <asp:PlaceHolder ID="PH" runat="server"></asp:PlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        
    </div>
    </form>
</body>
</html>

效果图:

技术分享

说明:

 

PlaceHolder控件的使用

原文:http://www.cnblogs.com/YanYongSong/p/5375060.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!