我有个用户控件Mypage.ascx,用户控件Mypage.ascx.cs中有个方法 public  void initpage() 
我现在想在Default.aspx页面调用initpage()方法,怎么办

解决方案 »

  1.   

    aspx:<%@ Register TagPrefix="aspx" TagName="mypage" Src="~/mypage.ascx" %><aspx:mypage runat="server" ID="ppMyPage" />
    aspx.csppMyPage.initpage();
      

  2.   


    在你的Code-Behind文件里要引用你的用户控件的Namespace才可以。
      

  3.   

    我的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();