2009-11-06 48 views
-1

所以我有以下結構;從ContentPage訪問MasterPage上的HtmlGenericControl

Start.master(Start.master.cs)

包含方法

DoSomething(string Text) 
{ 
    _MyHtmlControl.InnerText = Text; 
} 

而且HtmlGenericControl ID'ed _MyHtmlControl

Page.aspx(頁。 aspx.cs)

通過new Start().DoSomething("Test");調用方法

這樣做會給我以下錯誤:未將對象引用設置爲對象的實例。

如何讓它工作,所以我可以撥打DoSomething(),它將給定的字符串寫入MasterPage中定義的HtmlGenericControl?

回答

1

參見:

ASP.Net Master Pages: Tips, Tricks, and Traps

Abstract Interaction

Now it’s time to have the master page and content page interact. There are different approaches we can take to achieve interaction, but the best approaches are the ones that use the master page for what it is: a user control.

+0

非常感謝,你怎麼從來不靠自己的搜索時,發現這樣的有用的網站? -.-」 – 2009-11-06 13:07:23

相關問題