AutoCompleteExtender : Plusieurs usercontrol dans une page
Bonjour!
J'ai créé un WebUserControl contenant un textbox et un composant ajaxToolkit:AutoCompleteExtender.
Le WebUserControl fonctionne tres bien en utilisation seul. Il fonctionne aussi tres bien en edition dans un GridView.
Mais j'ai un problème lorsque je veut afficher plusieur fois le WebUserControl.
Le premier conflis a été une erreur javascript indiquant la presence sur la meme pages de deux id identique.
Pour contourner ce probleme je redefinis dans chaque WebUserControl la valeur de la propriété "BehaviorID".
Les deux composants marchent alors bien en l'absence des animations presentent dans mon composant ajaxToolkit:AutoCompleteExtender.
En effet les animations recherche le composant selon le "BehaviorID" et celui-ci est defini en dur dans le code.
Auriez vous une idée de la maniere a modifier le code pour qu'il prenne dynamiquement la bonne valeur de la propriété "BehaviorID" lors de la recherche du composant ajaxToolkit:AutoCompleteExtender?
Merci
Ci dessous mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
<asp:TextBox ID="TextBoxPointRemarquable" runat="server" autocomplete="off" SkinID="skinLibelleLong" ToolTip="<%$ Resources:POINT_REMARQUABLE_TOOLTIP %>"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtenderPointRemarquable"
runat="server"
BehaviorID="AutoCompleteEx"
TargetControlID="TextBoxPointRemarquable"
ServiceMethod="GetListePointRemarquable"
ServicePath="~/WebServices/PointRemarquableWS.asmx"
CompletionInterval="20"
MinimumPrefixLength="2"
EnableCaching="true"
CompletionSetCount="12"
UseContextKey="True" SkinID="green"
OnClientItemSelected="AutoCompleteExtenderPointRemarquable_ClientItemSelected">
<Animations>
<OnShow>
<Sequence>
<OpacityAction Opacity="0" />
<HideAction Visible="true" />
<ScriptAction Script="
// Cache the size and setup the initial size
var behavior = $find('AutoCompleteEx');
if (!behavior._height) {
var target = behavior.get_completionList();
behavior._height = target.offsetHeight - 2;
target.style.height = '0px';
}" />
<Parallel Duration=".4">
<FadeIn />
<Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" />
</Parallel>
</Sequence>
</OnShow>
<OnHide>
<Parallel Duration=".4">
<FadeOut />
<Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" />
</Parallel>
</OnHide></Animations>
</ajaxToolkit:AutoCompleteExtender>
<script type="text/javascript">
$addHandler($get('<%=TextBoxPointRemarquable.ClientID%>'), 'keypress', function(){
$get('<%=HiddenFieldIdPointRemarquable.ClientID %>').value = '';
alert(GetBehaviorID());
});
$addHandler($get('<%=TextBoxPointRemarquable.ClientID%>'), 'keydown', function(sender, e){
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
if (keycode != 13 && keycode != 9)
{
$get('<%=HiddenFieldIdPointRemarquable.ClientID %>').value = '';
}
});
var AutoCompleteExtenderPointRemarquable_ClientItemSelected = function(sender, e){
$get('<%=HiddenFieldIdPointRemarquable.ClientID %>').value = e.get_value();
}
</script>
<asp:HiddenField ID="HiddenFieldIdPointRemarquable" runat="server" /> |