abstract:在.net web項(xiàng)目中碰到一個(gè)比較奇怪的問題,網(wǎng)上沒找到解決方案,先自己mark一下問題描述:添加一個(gè)用戶控件ascx,在后端.cs添加js注冊(cè)腳本,執(zhí)行后沒有彈出框注冊(cè)腳本為:this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script typ
在.net web項(xiàng)目中碰到一個(gè)比較奇怪的問題,網(wǎng)上沒找到解決方案,先自己mark一下
問題描述:
添加一個(gè)用戶控件ascx,在后端.cs添加js注冊(cè)腳本,執(zhí)行后沒有彈出框
注冊(cè)腳本為:
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('提示');</script>");this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('提示');</script>");
網(wǎng)上找了些資料都是在aspx的后端cs頁面添加注冊(cè)代碼
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('提示');</script>");
在aspx頁面的后端cs頁面注冊(cè)的腳本執(zhí)行后會(huì)彈出alert框
對(duì)比兩段代碼個(gè)人覺得是因?yàn)樵赼scx.cs頁面的this.Page沒有取到當(dāng)前的aspx頁面,腳本沒有注冊(cè)成功,但是打斷點(diǎn)執(zhí)行的時(shí)候this.Page顯示的是當(dāng)前aspx頁面,所以不明白哪里出問題了