1
我正在谷歌搜索,有没有什么办法可以在运行时在我的页面中添加任何方法。我从stackoverflow获得了一个链接,这是expando对象。从ascx动态添加静态方法在aspx页
我不熟悉expando对象。这里是根据我的情况,我需要在许多aspx页面添加例行下面像 的代码小片段我有和喜欢
namespace DynamicDemo
{
class ExpandoFun
{
public static void Main()
{
Console.WriteLine("Fun with Expandos...");
dynamic student = new ExpandoObject();
student.FirstName = "John";
student.LastName = "Doe";
student.Introduction=new Action(()=>
Console.WriteLine("Hello my name is {0} {1}",student.FirstName,student.LastName);
);
);
Console.WriteLine(student.FirstName);
student.Introduction();
}
}
}
。
[WebMethod]
public static string LoadData(string CountryCode,int PageIndex)
{
string strData = "";
if (CountryCode != "")
{
strData = Left1.HavingCountry(CountryCode, PageIndex);
}
else
{
strData = Left1.WithoutCountry(PageIndex);
}
return strData;
}
,所以我需要知道,有没有什么办法来加入我的ascx页面的一些技术将在所有的aspx页面的主机特定的ascx添加上述方法。请帮我实现它。谢谢