在ASP.NET開發上,我們可能會使用.NET Framework中的ICallbackEventHandler來加速我們開發Ajax的應用。不過因為頁面上的PostBack會透過Ajax的方式來執行背後的Form Submit動作,所以如果在開發測試階段,程式上發生的錯誤,不會在頁面上顯示,所以常常造成頁面沒有反應,也不知道錯誤在哪裡....
會造成CallBack沒有執行成功,並回傳資料到前端網頁,大致可以區分兩部份問題,就是:
1.前端Submit就發生錯誤,沒有真正回到後端進行後續處理
2.後端處理產生錯誤,導致沒有辦法繼續回傳資料到前端
除了藉由Visual Studio的除錯工具外,可以簡單在第一時間抓出問題方向,可以利用在頁面上放置一個Button元件,直接手動執行PostBack動作,錯誤就會於頁面上顯示啦!一個簡單快速的除錯技巧:)
2008/04/18
2008/03/06
[原來如此]之Web Controls的ViewState無法保存
以下兩段子控制項的處理,會造成ViewState的結果不同(前者在Table Cell的Text無法Keep於ViewState中,後者才是正解) :
(1)
protected void Page_Load(object sender, EventArgs e)
{
Table t1 = new Table();
t1.Rows.Add(new TableRow());
t1.Rows[0].Cells.Add(new TableCell());
if (!this.IsPostBack)
{
t1.Rows[0].Cells[0].Text = "Text";
}
this.Controls.Add(t1);
}
(2)
protected void Page_Load(object sender, EventArgs e)
{
Table t1 = new Table();
this.Controls.Add(t1);
t1.Rows.Add(new TableRow());
t1.Rows[0].Cells.Add(new TableCell());
if (!this.IsPostBack)
{
t1.Rows[0].Cells[0].Text = "Text";
}
}
以上對於.NET元件開發上, 非常重要哦! 花了我8個小時的小差異大問題!
(1)
protected void Page_Load(object sender, EventArgs e)
{
Table t1 = new Table();
t1.Rows.Add(new TableRow());
t1.Rows[0].Cells.Add(new TableCell());
if (!this.IsPostBack)
{
t1.Rows[0].Cells[0].Text = "Text";
}
this.Controls.Add(t1);
}
(2)
protected void Page_Load(object sender, EventArgs e)
{
Table t1 = new Table();
this.Controls.Add(t1);
t1.Rows.Add(new TableRow());
t1.Rows[0].Cells.Add(new TableCell());
if (!this.IsPostBack)
{
t1.Rows[0].Cells[0].Text = "Text";
}
}
以上對於.NET元件開發上, 非常重要哦! 花了我8個小時的小差異大問題!
訂閱:
文章 (Atom)

