亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請問如下這是為什么呢?如何解決?

請問如下這是為什么呢?如何解決?

不負相思意 2023-01-12 19:15:30
.aspx文件中的部分代碼如下:<asp:ScriptManager ID="ScriptManager2" runat="server"></asp:ScriptManager><asp:UpdatePanel ID="UpdatePanel3" runat="server"><ContentTemplate><asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" Width="205px"OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList></ContentTemplate></asp:UpdatePanel><asp:UpdatePanel ID="UpdatePanel4" runat="server"><ContentTemplate><asp:ListBox ID="ListBox1" runat="server" Height="109px" Width="209px"></asp:ListBox></ContentTemplate><Triggers><asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" /></Triggers></asp:UpdatePanel>.aspx.cs文件的部分代碼如下:protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e){fun1();fun2();//兩個函數都是訪問后臺數據庫}問題是:當我選擇下拉框時,整個頁面任然在刷新。用debug看后,發現DropDownList1_SelectedIndexChanged函數執行完后,將繼續執行Page_Load函數。請問這是為什么呀?怎么解決呢?注:我用的是vs2008。聽取以上回答的意見后,我更改了一些代碼,如下:.aspx文件:<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"><ContentTemplate><asp:DropDownList ID="DSort1" runat="server" AutoPostBack="True" Width="205px" OnSelectedIndexChanged="DSort1_SelectedIndexChanged"></asp:DropDownList><asp:ListBox ID="LSort2" runat="server" Height="109px" width="209px"></asp:ListBox></ContentTemplate><Triggers><asp:AsyncPostBackTrigger ControlID="DSort1" EventName="SelectedIndexChanged" /></Triggers></asp:UpdatePanel> .cs文件:Page_Load事件加上 if(!IsPostBack),它和DSort1_SelectedIndexChanged函數里面的函數都是doWorks_getSort1();doWorks_getSort2();(從數據庫中讀數據到列表框中)。但是,改變下拉框的選項時,整個頁面任然在刷新,debug測試發現,執行完DSort1_SelectedIndexChanged函數后,將會執行Page_UnLoad函數。
查看完整描述

3 回答

?
BIG陽

TA貢獻1859條經驗 獲得超6個贊

AutoPostBack="True" 
自動回發給服務器 每次觸發selectedIndexChanged事件 就會把相關數據傳給服務 服務器處理完selectedIndexChanged事件后, 重新生成頁面傳給客戶端,故會執行page_load
你可以在page_load事件中判斷是不是回發處理頁面 if (!ispostback){這里面的代碼只在頁面第一次加載時執行}

查看完整回答
反對 回復 2023-01-15
?
慕仙森

TA貢獻1827條經驗 獲得超8個贊

在if(!IsPostBack)里后加上doWorks_getSort1();doWorks_getSort2();
后再加上response.end()試試.
這樣的話就會關閉流輸出.
我也沒試過,憑感覺的

查看完整回答
反對 回復 2023-01-15
?
RISEBY

TA貢獻1856條經驗 獲得超5個贊

幾個問題:
第一,感覺你沒有必要用兩個UpdatePanel
第二,Triggers只對外面的控件有效,因為你外面的控件在另一個UpdatePane里面,所以它找不到UpdatePane里面的控件
第三,Triggers只有當UpdatePane的UpdateMode屬性設置為Conditional時才有效,你改成以下試試

查看完整回答
反對 回復 2023-01-15
  • 3 回答
  • 0 關注
  • 158 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號