קה פרובלמה מואי צ'יקיטה?
ב-Microsoft AJAX קיים פקד חדש בשם UpdatePanel. בדיוק כמו Panel רגיל הוא מכיל בתוכו פקדים אחרים, אך בנוסף ליכולות של Panel רגיל יש לו יכולות AJAXיות. כל פקד שנמצא בתוך ה-UpdatePanel יכול להתרפרש בצורה דינמית ע"י טריגרים מסויימים. טריגרים לדוגמה ל-UpdatePanel שיגרמו לתוכן שלו להתרפרש: לחיצה כל כפתור, שינוי טקסט ב-TextBox, סימון CheckBox וכמו ששאלת בחירת ערך ב-DropDownList. בתוך האירועים שמתאימים לטריגרים שמים את הקוד שרוצים שישנה את הפקדים בתוך ה-Panel. למשל, במקרה שלנו יהיה לנו מחוץ ל-UpdatePanel פקד DropDownList רגיל לחלוטין.
<asp

ropDownList ID="DropDownList1" runat="server"> <asp:ListItem>www.JustinAngel.Net</asp:ListItem> <asp:ListItem>blogs.Microsoft.co.il</asp:ListItem> </asp

ropDownList>
נרצה ששינוי של ערך ב-DropDownList יגרום לשינוי כלשהו בדף ונרצה שהוא יהיה AJAXי ולכן נשנה קלות את הקוד של ה-DropDownList שישקף זאת
<asp

ropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem>www.JustinAngel.Net</asp:ListItem> <asp:ListItem>blogs.Microsoft.co.il</asp:ListItem> </asp

ropDownList>
נוסיף לדף UpdatePanel שאמרנו שנרצה שהפקדים בו ישתנו עם שינוי הערך הנבחר ב-DropDownList.
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel>
עכשיו נכניס לתוך ה-UpdatePanel שלנו GridView שהמטרה שלה היא להציג לנו את הערך שנבחר כרגע ב-DropDownList:
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" /> </Triggers> <ContentTemplate> <asp:GridView runat="server" ID="GridView1" /> </ContentTemplate> </asp:UpdatePanel>
עכשיו נדאג כי האירוע SelectedIndexChanged יקושר ל-GridView כך שידאג לשנות אותו לערך הנבחר:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { GridView1.DataSource = new string[] {DropDownList1.SelectedItem.Text}; GridView1.DataBind(); }
כל הקוד הזה לכאורה (ובמיוחד ה-AutoPostBack על ה-DropDownList) היו אמורים לגרום לרפרוש של הדף, אבל הם לא. הכל מתבצע בשורה שקטה ואכן הטקסט הנבחר מופיע בתוך ה-GridView.