2012-07-23 85 views
1

Possible Duplicate:
Retrieve contents of HtmlGenericControl inside ASCX WebControl檢索特定元素的HTML中ASCX

我有內嵌在多個頁面的ASCX控制從數據庫拉頁上下文相關的數據,將其綁定到一箇中繼器,然後有一個Button_Click事件,將電子郵件發送中繼器的內容給用戶。

我在拉數據服務器端時遇到問題。我試圖用傳統的方法(代碼裏面的ASCX的後面),例如:

var sw = new System.IO.StringWriter(); 
var hw = new HtmlTextWriter(sw); 
quotecontent.RenderControl(hw); 

但我發現了一個錯誤:

RegisterForEventValidation can only be called during Render(); 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: RegisterForEventValidation can only be called during Render(); 

這聽起來像我可能無法使用HtmlTextWriter在一個ASCX文件裏面?這是真的還是我做錯了?如果確實如此,我應該如何訪問元素的內容?

(這是一個問題,因爲Button_Click發生在ASCX用戶控件的代碼中,而不是ASPX頁面,在該頁面有這不是一個選項。)

+0

得到這個結果,這是關係到ASP.NET開發?和/或C#? 'html'和'render'標籤看起來沒有幫助/正確。考慮改變這些其他標籤是否準確。 – 2012-07-23 23:42:29

+0

完成。接得好。 – Wesley 2012-07-23 23:50:30

+0

如果我的理解是正確的,當按下按鈕時,您需要找回先前綁定到中繼器的數據以通過電子郵件發送它? – Jupaol 2012-07-24 00:03:48

回答