调用用户控件中的方法 我有个用户控件Mypage.ascx,用户控件Mypage.ascx.cs中有个方法 public void initpage() 我现在想在Default.aspx页面调用initpage()方法,怎么办 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 aspx:<%@ Register TagPrefix="aspx" TagName="mypage" Src="~/mypage.ascx" %><aspx:mypage runat="server" ID="ppMyPage" />aspx.csppMyPage.initpage(); 在你的Code-Behind文件里要引用你的用户控件的Namespace才可以。 我的default.aspx的页面如下<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register TagPrefix="aspx" TagName="mypage" Src="mypage.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"><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td><asp:DataList ID="DataList1" runat="server" Width="533px"><ItemTemplate><table cellpadding="0" cellspacing="0" border="0" width="99%"><tr ><td style="width:20%">测试</td><td style="width:80%"><%#Eval("name") %></td></tr></table></ItemTemplate></asp:DataList></td></tr><tr><td><aspx:mypage runat="server" ID="ppMyPage" /> </td></tr></table> </form></body></html>default.aspx.cs页面的代码:ppMyPage.只有几个tostring,equal之类的没有ppMyPage.initpage(); 贪吃蛇的那点事 C# textBox控件Enabled=false状态,设置字体显示为黑色 关于API函数的参数 vs2005自带的安装程序可不可以创建绝对目录? 局域网传输文件 DataGridView的CauseValidation属性设为了False, 怎样保存更改内容? 遇到一个奇怪的问题,请大家来看看! 简单问题 c#应怎样一步一步学习? 存储过程调用非常奇怪问题? C#操作WORD设置底纹无效 一个xpath查询的问题
aspx.csppMyPage.initpage();
在你的Code-Behind文件里要引用你的用户控件的Namespace才可以。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register TagPrefix="aspx" TagName="mypage" Src="mypage.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">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td>
<asp:DataList ID="DataList1" runat="server" Width="533px">
<ItemTemplate>
<table cellpadding="0" cellspacing="0" border="0" width="99%">
<tr >
<td style="width:20%">测试</td>
<td style="width:80%"><%#Eval("name") %></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
<tr>
<td>
<aspx:mypage runat="server" ID="ppMyPage" />
</td>
</tr>
</table>
</form>
</body>
</html>
default.aspx.cs页面的代码:ppMyPage.只有几个tostring,equal之类的没有ppMyPage.initpage();