假设放用户控件的页面为:WebForm1.aspx,用户控件为:WebUserControl1.ascx。
为用户控件传递参数只需要在用户控件WebUserControl1.ascx中添加属性,在WebForm1.aspx中为用户控件传入参数就可以了。例如:<uc1:webusercontrol1 id="WebUserControl11" runat="server" Para="传递参数"></uc1:webusercontrol1>。以下是代码:
WebForm1.aspx
<%
...
@ Register TagPrefix="uc1" TagName="WebUserControl1" Src="WebUserControl1.ascx"
%>
<% ... @ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
< HTML >
< HEAD >
< title > WebForm1
<% ... @ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
< HTML >
< HEAD >
< title > WebForm1