2011-12-01 21 views
5

私はしばらくこのことを試していましたが、周りを回ることができません。 aspxページ表示のコードを以下に示します。更新パネルがコンテンツを更新していない

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    Test<br /> 
    <asp:DropDownList ID="DropDownList1" runat="server"> 
     <asp:ListItem>1</asp:ListItem> 
     <asp:ListItem>2</asp:ListItem> 
    </asp:DropDownList> 
    <asp:ScriptManager ID="ScriptManager1" runat="server"> 
    </asp:ScriptManager> 
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
     <ContentTemplate> 
      <br /> 
      <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
    </ContentTemplate> 
    </asp:UpdatePanel> 
    </form> 
</body> 
</html> 

次はボタン1クリックイベントのコードです:

Public Class WebForm1 
    Inherits System.Web.UI.Page 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

    End Sub 

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList1.SelectedIndexChanged 
     Label1.Text = DropDownList1.SelectedIndex 

     UpdatePanel1.Update() 

    End Sub 
End Class 

あなたは私が逃したものを私に教えてもらえます。

答えて

2

ドロップダウンでautopostbackをtrueに設定します。

trueは、ドロップダウンの値が変更されるたびに、サーバーへのポストバックが発生することを意味します。

しかし、ティム・シュメルターの答えを聞いてください。ドロップダウンが変更されない場合は、更新パネルの外側に配置することをお勧めします。また、更新パネルをドロップダウンによって非同期に起動する必要があります(更新パネルにトリガーを設定しないと、更新パネル)。ドロップダウンの内容が変更された場合は、updatepanelの中​​に入れます。

しかし、私が言ったように、私は長い間、私はその件について私が言っていることすべてをチェックすることをお勧めします。 = p

PS:Microsoft Updateパネルは簡単に開発できますが、サイトは非常に遅くなります。 aspnet webservicesとjQueryについて学びましょう。

+0

。しかし、オートポストバックが何をしているのか教えてください。 – surpavan

+0

ありがとうございました。それは役に立ちます。 – surpavan

1

Scriptmanagerを使用するコントロールの前にScriptmanagerを配置する必要があります。

ドロップダウンリストコントロールの上に配置します。 また、selectedindexchangeイベントのドロップダウンリストでAutoPostBackプロパティをtrueに設定する必要があります。

<body> 
    <form id="form1" runat="server"> 
    <asp:ScriptManager ID="ScriptManager1" runat="server" /> 

    Test<br /> 
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostback="true"> 
     <asp:ListItem>1</asp:ListItem> 
     <asp:ListItem>2</asp:ListItem> 
    </asp:DropDownList> 

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
     <ContentTemplate> 
      <br /> 
      <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
    </ContentTemplate> 
    </asp:UpdatePanel> 
    </form> 
</body> 
+0

ありがとうございました。 – surpavan

1

あなたのDropDownListにTrueAutoPostbackを設定するのを忘れています。デフォルトはFalseです。

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.autopostback.aspx

そして、あなたは、ユーザーがDropDownListコントロールを変更した場合、あなたのUpdatePanelで非同期ポストバックをトリガーにしたい場合はドロップダウンがそれの外側にあるので、あなたは、UpdatePanelのためAsyncPostbackTriggerを指定する必要があります。別にあなたがEd saidとして冒頭でのScriptManagerを配置する必要があることから、

<Triggers> 
    <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" /> 
</Triggers> 

。 ASP.NET Ajaxの-の詳細に関する情報のためにここを見て:以下 http://msdn.microsoft.com/en-us/magazine/cc163354.aspx

+0

ありがとうございました。 – surpavan

1

が正しいマークアップで、ちょうどあなたのページにそれを置く:問題を解決し

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    Test<br /> 
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostback ="True"> 
     <asp:ListItem>1</asp:ListItem> 
     <asp:ListItem>2</asp:ListItem> 
    </asp:DropDownList> 
    <asp:ScriptManager ID="ScriptManager1" runat="server"> 
    <Triggers> 
     <asp:AsyncPostBackTrigger ControlID="DropDownList1" 
       EventName="SelectedIndexChanged" /> 
    </Triggers> 
    </asp:ScriptManager> 
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
    <ContentTemplate> 
     <br /> 
     <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
</ContentTemplate> 
</asp:UpdatePanel> 
</form> 

関連する問題