2013-01-09 88 views
0

我已经使用更新面板在asp.net webform页面中做部分回发,但不是部分加载它重新加载空白页面,我用combobox做回发onSelectIndexChanged事件 我的代码:asp.net更新面板仍然刷新页面

背后
<asp:UpdatePanel runat="server" ID="updatePanel1" > 
      <ContentTemplate> 
       <table style="direction:rtl;width:416px;" runat="server" clientidmode="Static"> 
       <tr class="trwidth"> 
       <td> 
        <asp:DropDownList ID="comboCategory" runat="server" 
         DataTextField="job_name" DataValueField="job_cat_id" DataSourceID="SqlDataSource1"> 
        </asp:DropDownList> 
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
         ConnectionString="<%$ ConnectionStrings:JobsConnectionString %>" 
         SelectCommand="SELECT * FROM [job_category]"></asp:SqlDataSource> 
       </td> 
        <td> 

           <asp:DropDownList ID="comboCountry" runat="server" AutoPostBack="True" ClientIDMode="Static" DataSourceID="SqlDataSource3" 
            OnSelectedIndexChanged="comboCountry_OnSelectedIndexChanged" 
            DataTextField="country_name" DataValueField="country_id">   
            </asp:DropDownList> 
           <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
            ConnectionString="<%$ ConnectionStrings:JobsConnectionString %>" 
            SelectCommand="SELECT * FROM [country]"></asp:SqlDataSource>   
           </td> 
          </tr> 
          <tr class="trwidth"> 
          <td> 

           <asp:DropDownList ID="comboCity" runat="server" DataSourceID="SqlDataSource2" ClientIDMode="Static" 
            DataTextField="city_name" DataValueField="location_id"> 
           </asp:DropDownList> 
           <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:JobsConnectionString %>" 
            SelectCommand="SELECT * FROM [location]"></asp:SqlDataSource> 
       </td>  
       <td> 

        <asp:DropDownList ID="comboGender" runat="server" 
         DataSourceID="SqlDataSource4" 
         DataTextField="gender_name" DataValueField="gender_id" ClientIDMode="Static"> 

        </asp:DropDownList> 
        <asp:SqlDataSource ID="SqlDataSource4" runat="server" 
         ConnectionString="<%$ ConnectionStrings:JobsConnectionString %>" 
         SelectCommand="SELECT * FROM [gender]"></asp:SqlDataSource> 
       </td> 

       </tr> 
       <tr class="trwidth"> 
       <td colspan="2" style="text-align:center;padding-left: 130px;direction: ltr"> 
        <dx:ASPxDateEdit ID="ASPxDateEdit" runat="server" NullText="دوا بەروار"> 
        </dx:ASPxDateEdit> 
        </td> 
       </tr> 
       <tr class="trwidth"><td></td> 
        <td class="dxtcLeftAlignCell"> 
        </td> 
        <td></td><td></td></tr> 
       <tr class="trwidth"><td>&nbsp;</td> 
        <td class="dxtcLeftAlignCell"> 
         &nbsp;</td> 
        <td>&nbsp;</td> 
        <td>&nbsp;</td> 

       </tr> 
       </table> 

      </ContentTemplate> 
     </asp:UpdatePanel> 

代码:

protected void comboCountry_OnSelectedIndexChanged(object sender, EventArgs e) 
     { 
      try 
      { 
       SqlDataSource2.SelectCommand = "SELECT * FROM [location] where [country_id]=" + 
               comboCountry.SelectedValue; 
       comboCity.DataBind(); 
      } 
      catch (Exception exception) 
      { 
       Debug.WriteLine(exception.Message); 

}}

+1

检查ScriptManager控件的'EnablePartialRendering'属性。 –

回答

2

因此,我看不出有任何问题与标记-U p - 你是否在后面的代码中设置了所有的updatepanel属性?

另一次尝试,可能是使用显式触发声明或登记 - 比如

<asp:UpdatePanel runat="server" ID="updatePanel1" > 
    <Triggers> 
     <asp:AsyncPostBackTrigger ControlID="comboCountry" /> 
    </Triggers> 
    ... 

或类似代码如

ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(comboCountry); 

你也可以尝试改变那些组合框ClientIDMode来自动识别或预测。

+0

谢谢你的问题是ClientIDMode =“Static” – danarj