2012-06-28 27 views

回答

0

首先,創建webusercontrol

WebUserControl1.ascx

此代碼是

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication1.WebUserControl1" %> 
<asp:Label ID="label" runat="server" > 
     </asp:Label> 
     <table> 
      <tr> 
       <td> 
       </td> 
       <td> 
        <asp:TextBox ID="textbox1" runat="server"></asp:TextBox> 
       </td> 
      </tr> 
      <tr> 
       <td> 

       </td> 
       <td> 
        <asp:TextBox ID="textbox2" runat="server"></asp:TextBox> 
       </td> 

      </tr> 
      <tr> 
       <td> 
       </td> 
       <td> 
        <asp:TextBox ID="textbox3" runat="server"></asp:TextBox> 
       </td> 

      </tr> 
      <tr> 
       <td> 
       </td> 
       <td> 
        <asp:TextBox ID="textbox4" runat="server"></asp:TextBox> 
       </td> 

      </tr> 
      <tr> 
       <td> 
       </td> 
       <td> 
        <asp:TextBox ID="textbox5" runat="server"></asp:TextBox> 
       </td> 

      </tr> 
     </table> 

背後添加此代碼爲您的用戶控件

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

namespace WebApplication1 
{ 
    public partial class WebUserControl1 : System.Web.UI.UserControl 
    { 
     public string MyProperty { get; set; } 

     protected void Page_Load(object sender, EventArgs e) 
     { 
      label.Text = MyProperty; 
     } 
    } 
} 

其次創建你的aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %> 
<%@ Register TagName="test" TagPrefix="uc" Src="~/WebUserControl1.ascx" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 

    <uc:test id="uc1" runat="server" MyProperty="Texte1"></uc:test> 
    <uc:test id="uc2" runat="server" MyProperty="Texte2"></uc:test> 
    <uc:test id="uc3" runat="server" MyProperty="Texte3"></uc:test> 
    <uc:test id="uc4" runat="server" MyProperty="Texte4"></uc:test> 


    </div> 
    </form> 
</body> 
</html> 
+0

請模擬一下/ ...它高於我的頭 – user1489577

+0

http://moblog.bradleyit.com/2009/04/creating-sections-in-sharepoint-forms.html請看看並告訴我如何實現它 – user1489577

+0

1.因爲你想創建通用控件,然後用.net你可以創建一個用戶控件,然後我創建用戶控件,這個控件有兩個部分:aspx和aspx.cs,並且這個控件必須注入你的頁面,然後我用aspx擴展名創建頁面,然後我注入usercontrol,嘗試使用代碼 –

相關問題