Ajax et ASP.NET

asenaici Messages postés 2 Date d'inscription jeudi 25 avril 2002 Statut Membre Dernière intervention 24 février 2009 - 17 févr. 2009 à 10:58
asenaici Messages postés 2 Date d'inscription jeudi 25 avril 2002 Statut Membre Dernière intervention 24 février 2009 - 24 févr. 2009 à 10:18
Bonjour

J'ai placé 12 objets Button et 12 objets Panel sur un UpdatePanel.
Au click d'un bouton, un panel apparait (sur l'évenement OnClik, le panel
précédent devient invisible, et le nouveau panel devient visible)

Est-ce normal que malgré l'objet ScriptManager et l'UpdatePanel, quand je clique sur un bouton, la fenêtre se rafraichit ?
Il me semblait qu'avac Ajax, il n'y avait aucun rafraichissement

Merci d'avance pour votre aide :-)

<!-- / message -->

Ci-joint les sources aspx et cs

Source aspx
<%

@
Page
Language="C#"
AutoEventWireup="true"
CodeFile="GestionAgenda2.aspx.cs"
Inherits="GestionAgenda"
StyleSheetTheme="ThŠme1" %><%

@
Register
assembly="AjaxControlToolkit"
namespace="AjaxControlToolkit"
tagprefix="cc1" %><%

@
Register
assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
namespace="System.Web.UI"
tagprefix="asp" %>
<!

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>Page sans titre
</title>

<style
type="text/css">

.style26{

color:
#0066FF;

font-weight:
bold;

height:
23px;}

</style></

head><

body>

<form
id="form1"
runat="server">

<div
style="width:
731px;
height:
49px">

<asp:ScriptManager
ID="ScriptManager1"
runat="server">

</asp:ScriptManager>

<br
/>

<br
/>

<br
/>

<br
/>

<br
/>

<asp:UpdatePanel
ID="UpdatePanel2"
runat="server">

<ContentTemplate>

<p
class="style26">

<asp:Button
ID="Bn01"
runat="server"
onclick="Bn01_Click"
Text="Janvier"
/>

<asp:Button
ID="Bn02"
runat="server"
onclick="Bn01_Click"
Text="F‚vrier"
/>

<asp:Button
ID="Bn03"
runat="server"
onclick="Bn01_Click"
Text="Mars"
/>

<asp:Button
ID="Bn04"
runat="server"
onclick="Bn01_Click"
Text="Avril"
/>

<asp:Button
ID="Bn05"
runat="server"
onclick="Bn01_Click"
Text="Mai"
/>

<asp:Button
ID="Bn06"
runat="server"
onclick="Bn01_Click"
Text="Juin"
/>

<asp:Button
ID="Bn07"
runat="server"
onclick="Bn01_Click"
Text="Juillet"
/>

<asp:Button
ID="Bn08"
runat="server"
onclick="Bn01_Click"
Text="Ao–t"
/>

<asp:Button
ID="Bn09"
runat="server"
onclick="Bn01_Click"
Text="Septembre"
/>

<asp:Button
ID="Bn10"
runat="server"
onclick="Bn01_Click"
Text="Octobre"
/>

<asp:Button
ID="Bn11"
runat="server"
onclick="Bn01_Click"
Text="Novembre"
/>

<asp:Button
ID="Bn12"
runat="server"
onclick="Bn01_Click"
Text="Decembre"
/>

</p>

<asp:Panel
ID="Panel1"
runat="server"
BackColor="Lime"
Height="125px">

<asp:CheckBoxList
ID="CheckBoxList1"
runat="server"
Height="97px"
Width="200px">

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:CheckBoxList>

</asp:Panel>

<asp:Panel
ID="Panel2"
runat="server"
BackColor="Yellow"
Height="125px"
Visible="False">

<asp:CheckBoxList
ID="CheckBoxList2"
runat="server"

Height="97px"
Width="200px">

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:CheckBoxList>

</asp:Panel>

<asp:Panel
ID="Panel3"
runat="server"
BackColor="Blue"
Height="125px"

Width="694px"
Visible="False">

<asp:CheckBoxList
ID="CheckBoxList3"
runat="server"

Height="97px"
Width="200px">

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:CheckBoxList>

</asp:Panel>

<asp:Panel
ID="Panel4"
runat="server"
BackColor="Lime"
Height="125px"

Width="694px"
Visible="False">

<asp:CheckBoxList
ID="CheckBoxList4"
runat="server"
Height="97px"
Width="200px">

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:CheckBoxList>

</asp:Panel>

<asp:Panel
ID="Panel5"
runat="server"
BackColor="Yellow"
Height="125px"

Width="694px"
Visible="False">

<asp:CheckBoxList
ID="CheckBoxList5"
runat="server"

Height="97px"
Width="200px">

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:CheckBoxList>

</asp:Panel>

<asp:Panel
ID="Panel6"
runat="server"
BackColor="Blue"
Height="125px"

Width="692px"
Visible="False">

<asp:CheckBoxList
ID="CheckBoxList6"
runat="server"

Height="97px"
Width="200px">

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:CheckBoxList>

</asp:Panel>

<asp:Panel
ID="Panel7"
runat="server"
BackColor="Lime"
Height="125px"

Width="694px"
Visible="False">

<asp:CheckBoxList
ID="CheckBoxList7"
runat="server"
Height="97px"
Width="200px">

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:CheckBoxList>

</asp:Panel>

<asp:Panel
ID="Panel8"
runat="server"
BackColor="Yellow"
Height="125px"

Width="694px"
Visible="False">

<asp:CheckBoxList
ID="CheckBoxList8"
runat="server"

Height="97px"
Width="200px">

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:CheckBoxList>

</asp:Panel>

<asp:Panel
ID="Panel9"
runat="server"
BackColor="Blue"
Height="125px"

Width="694px"
Visible="False">

<asp:CheckBoxList
ID="CheckBoxList9"
runat="server"

Height="97px"
Width="200px">

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:CheckBoxList>

</asp:Panel>

<asp:Panel
ID="Panel10"
runat="server"
BackColor="Lime"
Height="125px"

Width="694px"
Visible="False">

<asp:CheckBoxList
ID="CheckBoxList10"
runat="server"
Height="97px"
Width="200px">

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:CheckBoxList>

</asp:Panel>

<asp:Panel
ID="Panel11"
runat="server"
BackColor="Yellow"
Height="125px"

Width="694px"
Visible="False">

<asp:CheckBoxList
ID="CheckBoxList11"
runat="server"

Height="97px"
Width="200px">

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:CheckBoxList>

</asp:Panel>

<asp:Panel
ID="Panel12"
runat="server"
BackColor="Blue"
Height="125px"

Width="694px"
Visible="False">

<asp:CheckBoxList
ID="CheckBoxList12"
runat="server"

Height="97px"
Width="200px">

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:CheckBoxList>

</asp:Panel>

</ContentTemplate>

</asp:UpdatePanel>

</div>

<p
class="style26">Choix des p‚riodes
</p>

<p
class="style26">&nbsp;</p>

<p
class="style26">&nbsp;</p>

</form></

body></

html>Source cs
using

System;
using

System.Windows.Forms;
using

System.Collections;
using

System.Configuration;
using

System.Data;
using

System.Web;
using

System.Web.Security;
using

System.Web.UI;
using

System.Web.UI.HtmlControls;
using

System.Web.UI.WebControls;
using

System.Web.UI.WebControls.WebParts;
public

partial
class
GestionAgenda : System.Web.UI.
Page{

protected

void Bn01_Click(
object sender,
EventArgs e){
Panel1.Visible false;Panel2.Visible
false;Panel3.Visible false;Panel4.Visible
false;Panel5.Visible false;Panel6.Visible
false;Panel7.Visible false;Panel8.Visible
false;Panel9.Visible false;Panel10.Visible
false;Panel11.Visible false;Panel12.Visible

false; 

string chaine_numbtn = ((System.Web.UI.WebControls.
Button)sender).ID.Substring(2, 2);

int numbtn =
Convert.ToInt32(chaine_numbtn);System.Web.UI.WebControls.

Panel LePanel = (System.Web.UI.WebControls.
Panel)FindControl(
"Panel" + numbtn.ToString());LePanel.Visible =

true;}

}

féru de programmation. Mais j'en apprends tous les jours
merci pour ce site formidable  :-)

2 réponses

cs_Seb_P Messages postés 40 Date d'inscription mercredi 31 janvier 2007 Statut Membre Dernière intervention 23 février 2009
23 févr. 2009 à 11:15
Alors en fait c'est assez simple :D. Donc ton problème vient du fait que tout est dans un seul "update panel " du coup a chaque event il recharge l'update panel. Donc tu as 3 solutions :

1)Mettre  EnableEventValidation="false"  dans les parametres de page <%@ Page ...... EnableEventValidation="false"  %>
Ce qui aura pour effet de désactivé tout rafraichissement sur la page.

2) Sur l'update panel  tu as un parametre UpdateMode="Always" => a chaque envent ou UpdateMode="Conditional" => sur demande. si tu est en conditional il faut ensuit et faire l'update manuellement via ton code exemple : MonUpdatePanel.Update();

3)Tu divise en plusieurs update panel pour rafraichir par zone en tenant compte des deux solutions précédentes ^^

Voila j'espere avoir répondu a la question ;)
0
asenaici Messages postés 2 Date d'inscription jeudi 25 avril 2002 Statut Membre Dernière intervention 24 février 2009
24 févr. 2009 à 10:18
Merci beaucoup pour votre aide :-)


Je vais essayer


 


Merci encore






féru de programmation. Mais j'en apprends tous les jours
merci pour ce site formidable  :-)
0
Rejoignez-nous