IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET Discussion :

"The Controls collection cannot be modified because the control contains code blocks"


Sujet :

ASP.NET

  1. #1
    Membre éclairé
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2007
    Messages
    375
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 375
    Par défaut "The Controls collection cannot be modified because the control contains code blocks"
    Bonjour,

    J'ai cette erreur en ASP.NET
    The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:


    [HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
    System.Web.UI.ControlCollection.Add(Control child) +2108047
    SharePointCodeBehindPages.CodeBehindPosition.btManagePosition_Click(Object sender, EventArgs e) +1915
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +177
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746

    J'ai réussi à la localiser dans mon code, mais je n'arrive pas à résoudre le problème...
    J'ai pas mal googler, mais sans succès. Je bosse sous SharePoint, donc pas de possibilité de mettre un tag body avec runat = server.
    Ce code est dans un usercontrol également. Je pense que c'est bon de le préciser ^^

    Si vous avez une idée, ce serai chouette ^^
    Merci bien

  2. #2
    Membre chevronné
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2004
    Messages
    417
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Novembre 2004
    Messages : 417
    Par défaut
    tu aurais le code de ton UC surtout la ou tu utilise les <% %>
    pour voir.
    As tu essayer de passer par le Code behind plutôt que par l'utilisation de <% %>.

  3. #3
    Membre éclairé
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2007
    Messages
    375
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 375
    Par défaut
    C'est une fonction javascript en fait. Je l'appelle en javascript pour éviter de faire un postback.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    <%@ Control Language="C#" AutoEventWireup="true" 
        Inherits="SharePointCodeBehindPages.CodeBehindPosition, CodeBehindVSeWSS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" 
        meta:progid="SharePoint.WebPartPage.Document"%>
     
    <script type="text/javascript" >
    function ImageClicked(btn)
    {
        btn = "<%= UniqueID %>" + "$" + btn;
        alert(btn);
        __doPostBack(btn, '');
    }
     
    </script>
     
        <asp:Table ID="tablePosition" runat="server">
        </asp:Table>
    <hr />
    	<asp:Table runat="server">
    	    <asp:TableRow>
    	        <asp:TableCell>
                    <asp:Label ID="lbAffair" runat="server" Text="Select the Affair"></asp:Label>
    	        </asp:TableCell>
    	        <asp:TableCell>
                    <asp:DropDownList ID="ddlAffair" runat="server" 
                        onselectedindexchanged="ddlAffair_SelectedIndexChanged" DataTextField="DESIGNATIONAFFAIR" DataValueField="IDAFFAIR" AutoPostBack="true">
                    </asp:DropDownList>
    	        </asp:TableCell>
    	    </asp:TableRow>
    	    <asp:TableRow>
    	        <asp:TableCell>
                    <asp:Label ID="lbTower" runat="server" Text="Select the Tower"></asp:Label>
    	        </asp:TableCell>
    	        <asp:TableCell>
                    <asp:DropDownList ID="ddlTower" runat="server" 
                        onselectedindexchanged="ddlTower_SelectedIndexChanged" DataTextField="DESIGNATIONTOWER" DataValueField="IDTower" AutoPostBack="true">
                    </asp:DropDownList>
    	        </asp:TableCell>
    	    </asp:TableRow>
    	    <asp:TableRow>
    	        <asp:TableCell>
                    <asp:Label ID="lbTeam" runat="server" Text="Select the Team"></asp:Label>
    	        </asp:TableCell>
    	        <asp:TableCell>
                    <asp:DropDownList ID="ddlTeam" runat="server" 
                        onselectedindexchanged="ddlTeam_SelectedIndexChanged" 
                        DataTextField="DESIGNATIONTEAM" DataValueField="IDTEAM" AutoPostBack="true" 
                        style="height: 22px">
                    </asp:DropDownList>
    	        </asp:TableCell>
    	    </asp:TableRow>
    	    <asp:TableRow>
    	        <asp:TableCell>
                    <asp:Label ID="lbPosition" runat="server" Text="Select the Positon"></asp:Label>
    	        </asp:TableCell>
    	        <asp:TableCell>
                    <asp:DropDownList ID="ddlPosition" runat="server" 
                        onselectedindexchanged="ddlPosition_SelectedIndexChanged" DataTextField="DESIGNATIONPOSTE" DataValueField="IDPOSTE" AutoPostBack="true">
                    </asp:DropDownList>
    	        </asp:TableCell>
    	    </asp:TableRow>
    	    <asp:TableRow>
    	        <asp:TableCell>
                    <asp:Label ID="lbActualCategory" runat="server" Text="Actual Category"></asp:Label>
    	        </asp:TableCell>
    	        <asp:TableCell>
                    <asp:DropDownList ID="ddlActualCategory" runat="server" 
                        DataTextField="INTERNAL_CATEGORY" DataValueField="IDInternal_category">
                    </asp:DropDownList>
    	        </asp:TableCell>
    	    </asp:TableRow>
    	    <asp:TableRow>
    	        <asp:TableCell>
                    <asp:Label ID="lbProposedCategory" runat="server" Text="Proposed Category"></asp:Label>
    	        </asp:TableCell>
    	        <asp:TableCell>
                    <asp:DropDownList ID="ddlProposedCategory" runat="server" 
                        DataTextField="INTERNAL_CATEGORY" DataValueField="IDInternal_category">
                    </asp:DropDownList>
    	        </asp:TableCell>
    	    </asp:TableRow>
    	    <asp:TableRow>
    	        <asp:TableCell>
    	            <asp:Label ID="lbStartDateTeam" runat="server" Text="Start Date"></asp:Label>
    	        </asp:TableCell>
                <asp:TableCell>
                    <asp:TextBox ID="tbStartDateTeam" runat="server" MaxLength="11" tooltip="dd/mm/yyyy"></asp:TextBox>
                    <asp:Image id="ImageCalendarStartTeam" runat="server" ImageUrl="/_layouts/images/calendar.gif" AlternateText="Show Calendar" onClick="return ImageClicked('btnCalendarStartTeam');" style="cursor: hand;" />
     				<asp:button id="btnCalendarStartTeam" width="0" runat="server" style="visibility:hidden" onclick="ImageCalendarStartTeam_Click" CausesValidation="false"/>			
     
                    <asp:CompareValidator id="checkStartDateTeam" runat="server" ErrorMessage="Date format is 'dd/mm/yyyy'" ControlToValidate="tbStartDateTeam" Type="Date" Operator="DataTypeCheck" display="Dynamic"></asp:CompareValidator>
                    <asp:RequiredFieldValidator ID="RequieredStartDateTeam" runat="server" ErrorMessage="You need to set a date" ControlToValidate="tbStartDateTeam" />
                    <asp:CompareValidator ControlToValidate="tbStartDateTeam" ID="ckStartDateTeam" runat="server" Operator="GreaterThanEqual" Type="Date"
    	                Display="Dynamic" ErrorMessage="The employee didn't work at this date. Set a greater date." ValueToCompare="01/01/1900" />
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Calendar ID="CalendarStartTeam" runat="server"
                        visible="false" BackColor="White" 
                        BorderColor="White" BorderWidth="1px" Font-Names="Verdana" Font-Size="9pt" 
                        ForeColor="Black" NextPrevFormat="FullMonth" 
                        onselectionchanged="CalendarStartTeam_SelectionChanged">
                        <SelectedDayStyle BackColor="#333399" ForeColor="White" />
                        <TodayDayStyle BackColor="#CCCCCC" />
                        <OtherMonthDayStyle ForeColor="#999999" />
                        <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" 
                            VerticalAlign="Bottom" />
                        <DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
                        <TitleStyle BackColor="White" BorderColor="Black" BorderWidth="4px" 
                            Font-Bold="True" Font-Size="12pt" ForeColor="#333399" />
                    </asp:Calendar>            
                </asp:TableCell>
    	    </asp:TableRow>
    	    <asp:TableRow>
    	        <asp:TableCell>
    	            <asp:Label ID="lbEndDateTeam" runat="server" Text="End Date"></asp:Label>
    	        </asp:TableCell>
                <asp:TableCell>
                    <asp:TextBox ID="tbEndDateTeam" runat="server" MaxLength="11" tooltip="dd/mm/yyyy"></asp:TextBox>
                    <asp:Image id="ImageCalendarEndTeam" runat="server" ImageUrl="/_layouts/images/calendar.gif" AlternateText="Show Calendar" onClick="return ImageClicked('btnCalendarEndTeam');" style="cursor: hand;" />
     				<asp:button id="btnCalendarEndTeam" width="0" runat="server" style="visibility:hidden" onclick="ImageCalendarEndTeam_Click" CausesValidation="false"/>			
     
                    <asp:CompareValidator id="checkEndDateTeam" runat="server" ErrorMessage="Date format is 'dd/mm/yyyy'" ControlToValidate="tbEndDateTeam" 
                        Type="Date" Operator="DataTypeCheck" display="Dynamic"></asp:CompareValidator>
                    <asp:CompareValidator ControlToValidate="tbEndDateTeam" ID="ckEndDateTeam" runat="server" Operator="GreaterThanEqual" Type="Date"
    	                Display="Dynamic" ErrorMessage="End date must be greater than start date !"  ControlToCompare="tbStartDateTeam"/>
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Calendar ID="CalendarEndTeam" runat="server" visible="false"
                        BackColor="White" 
                        BorderColor="White" BorderWidth="1px" Font-Names="Verdana" Font-Size="9pt" 
                        ForeColor="Black" NextPrevFormat="FullMonth" 
                        onselectionchanged="CalendarEndTeam_SelectionChanged">
                        <SelectedDayStyle BackColor="#333399" ForeColor="White" />
                        <TodayDayStyle BackColor="#CCCCCC" />
                        <OtherMonthDayStyle ForeColor="#999999" />
                        <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" 
                            VerticalAlign="Bottom" />
                        <DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
                        <TitleStyle BackColor="White" BorderColor="Black" BorderWidth="4px" 
                            Font-Bold="True" Font-Size="12pt" ForeColor="#333399" />
                    </asp:Calendar>            
                </asp:TableCell>
    	    </asp:TableRow>
    	    <asp:TableRow>
    	        <asp:TableCell>
                    <asp:Button ID="btAddPosition" runat="server" Text="Add a position" CausesValidation="false"
    	            OnClick="btAddPosition_Click" />
    	            <asp:Button ID="btManagePosition" runat="server" Text="OK" ValidationGroup="EndDateTeam"
    	            OnClick="btManagePosition_Click" /> 
                </asp:TableCell>
    	        <asp:TableCell>
                    <asp:Button ID="btDepartureEmployee" runat="server" Text="The employee leaves ?" CausesValidation="false"
                    OnClick="btDepartureEmployee_Click" />
                    <asp:Button ID="btReturnPostion" runat="server" Text="Return"
    	            OnClick="btReturnPostion_Click" CausesValidation="false" />
    	        </asp:TableCell>
    	    </asp:TableRow>
    	    <asp:TableRow>
    	        <asp:TableCell>
    	            <asp:Label ID="lbDateDeparture" runat="server" Text="Date Departure :" />
    	        </asp:TableCell>
    	        <asp:TableCell>
    	            <asp:TextBox ID="tbDateDeparture" runat="server" MaxLength="11" />
     
    	        </asp:TableCell>
    	        <asp:TableCell>
                    <asp:Image id="ImageDateDeparture" runat="server" ImageUrl="/_layouts/images/calendar.gif" AlternateText="Show Calendar" onClick="return ImageClicked('btnDateDeparture');" style="cursor: hand;" />
     				<asp:button id="btnDateDeparture" width="0" runat="server" style="visibility:hidden" onclick="ImageDateDeparture_Click" CausesValidation="false"/>	
     
                    <asp:CompareValidator id="ckDepartureDate" runat="server" ErrorMessage="Date format is 'dd/mm/yyyy'" ControlToValidate="tbDateDeparture" 
    	                Type="Date" Operator="DataTypeCheck" display="Dynamic" ValidationGroup="DepartureDate"></asp:CompareValidator>
    	            <asp:CompareValidator ControlToValidate="tbDateDeparture" ID="ckDepartureDateGreater" runat="server" Operator="GreaterThanEqual"
    	                Display="Dynamic" ErrorMessage="End date must be greater than start date !" ValidationGroup="DepartureDate" />
     
                    <asp:RequiredFieldValidator ID="RequiredDepartureDate" runat="server" ErrorMessage="You need to set a date" 
                        ControlToValidate="tbDateDeparture" ValidationGroup="DepartureDate" />
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Calendar ID="CalendarDateDeparture" runat="server" visible="false"
                        Style="position:relative;" BackColor="White" 
                        BorderColor="White" BorderWidth="1px" Font-Names="Verdana" Font-Size="9pt" 
                        ForeColor="Black" NextPrevFormat="FullMonth" 
                        onselectionchanged="CalendarDateDeparture_SelectionChanged">
                        <SelectedDayStyle BackColor="#333399" ForeColor="White" />
                        <TodayDayStyle BackColor="#CCCCCC" />
                        <OtherMonthDayStyle ForeColor="#999999" />
                        <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" 
                            VerticalAlign="Bottom" />
                        <DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
                        <TitleStyle BackColor="White" BorderColor="Black" BorderWidth="4px" 
                            Font-Bold="True" Font-Size="12pt" ForeColor="#333399" />
                    </asp:Calendar> 
    	        </asp:TableCell>
    	    </asp:TableRow>
    	    <asp:TableRow>
    	        <asp:TableCell>
    	            <asp:Label ID="lbDepartureReason" runat="server" Text="Departure Reason :" />
    	        </asp:TableCell>
    	        <asp:TableCell>
    	            <asp:DropDownList ID="ddlDepartureReason" runat="server" DataTextField="DESIGNATIONDEPARTUREREASON"
    	                             DataValueField="IDDEPARTUREREASON" />
    	            <asp:RequiredFieldValidator ID="RequiredDepartureReason" runat="server" ErrorMessage="Please select a departure reason" 
                                ControlToValidate="ddlDepartureReason" InitialValue="Select the departure reason" 
                                    ValidationGroup="DepartureDate" Display="Dynamic"></asp:RequiredFieldValidator>
    	        </asp:TableCell>
    	    </asp:TableRow>
    	    <asp:TableRow>
    	        <asp:TableCell>
    	            <asp:Button id="btCancel" runat="server" Text="Cancel" CausesValidation="False"
    	            OnClick="btCancel_Click" />
    	        </asp:TableCell>
    	        <asp:TableCell>
    	            <asp:Button ID="btSaveDeparture" runat="server" Text="Save" ValidationGroup="DepartureDate"
    	            OnClick="btSaveDeparture_Click" />
    	        </asp:TableCell>
    	    </asp:TableRow>
    	</asp:Table>
     
    	<asp:Button ID="btDeleteRole" runat="server" Visible="true" style="visibility:hidden" OnClick="btDeleteRole_Click" OnClientClick="return confirm('Do you want to delete the roles of the employee ?')" CausesValidation="false" />
        <asp:Button ID="btAddRole" runat="server" Visible="true" style="visibility:hidden" OnClick="btAddRole_Click" OnClientClick="return confirm('Do you want to add the default roles of this position ?')" CausesValidation="false" />

  4. #4
    Membre chevronné
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2004
    Messages
    417
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Novembre 2004
    Messages : 417
    Par défaut
    Pourquoi ne as faire de RegisterStartupScript avec le Scriptclient?

    tu n'y as pas accés?
    Encore un truc à la sharepoint ?

  5. #5
    Membre éclairé
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2007
    Messages
    375
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 375
    Par défaut
    pourquoi ? Parce que je suis débutant et que j'apprends un peu au fur et à mesure.

    Est-ce que tu peux me parler rapidement de cette fonction ? Suite à ce que j'ai compris, c'est une fonction que tu met en général dans le page_load qui permet d'affecter un script javascript (ou autre) à un control ? Et tout ca, coté client. Si j'ai tout bien compris (je me surprendrais ! :p)

  6. #6
    Membre chevronné
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2004
    Messages
    417
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Novembre 2004
    Messages : 417
    Par défaut
    Lol tous le contraire je pensais que tu connaissais déja, c'est pour cela que je disais ca .

    Dans Page tu as un getter qui s'apelle ClientScript qui te permet de récuperer la classe ClientScriptManager et permet de gerer ton scriptManager (Pour cela il faut que tu ais dans ta page
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <asp:ScriptManager ID="_scriptManager" runat="server"></asp:ScriptManager>
    Moi elle est dans la MainPage car tu dois en avoir que un par page)

    Donc Grace a ClientScript Tu peux manager du javacsript coté serveur.
    Ex d'appel d'une fct:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    this.ClientScript.RegisterStartupScript(this.GetType(), "fct", "fct();", true);
    ex d'une fct inline:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "action", "Async.LoadProductGraph.GetGraphEs=function(graphType,commentCtrlId){var comment=$get(commentCtrlId);if(graphType=='intra')comment.textContent='Los datos y resultados aqui mostrados son indicativos y no tienen en cuenta la profundidad y horquillas del Activo Subyacente en mercado';else comment.textContent='Los precios del Subyacente son los precios de cierre oficiales. Los precios de los Warrants son los últimos precios enviados a mercado a las 17:30H';currentGraph.GraphType=graphType;currentGraph.execWebRequest()};", true);
    ex d'un alert tous simple:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ClientScript.RegisterStartupScript(GetType(), "ko", "alert('" + message + "');", true);
    evidement l'intérêt est que tu peux le mixer avec le C# pour avoir le rendu que tu veux.
    Moi j'utilise RegisterStartupScript parce que les appels que je fais dépende d'autre javascript inclus et ca permet d'inclure mon code une fois le tous chargé.

    En ésperant que ca t'aide

  7. #7
    Membre éclairé
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2007
    Messages
    375
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 375
    Par défaut
    Est-ce que je peux lier ca à un control ?
    Déclencher telle fonction quand l'utilisateur clique sur un control précis ?
    Quand tu dis que ca se passe coté serveur, ca veux dire que ca fait un postback ?

  8. #8
    Membre chevronné
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2004
    Messages
    417
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Novembre 2004
    Messages : 417
    Par défaut
    en fait quand ta pages est rendu c'est à ce moment la que le javascript est ajouté et génère par le serveur.

    Aprés pour le postBack ca dépend de ce que tu demande a ton javascript de faire.

    ex avec ton code:

    this.ClientScript.RegisterStartupScript(this.GetType(), "UrCode", "function ImageClicked(btn){btn = "+UniqueID+" + '$' + btn; alert(btn);__doPostBack(btn, '');}", true);


    Par contre je suis pas sur que ta fct marche si?.
    Que voudrais tu faire avec?

  9. #9
    Membre éclairé
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2007
    Messages
    375
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 375
    Par défaut
    Si, ma fonction fonctionne.
    En fait, j'avais un problème lorsque que j'appuyais sur la touche entrée, ca déclanchais mon imagebutton. Alors j'ai utilisé une image et un bouton caché.
    Lorsque je clique sur l'image, je passe l'id du bouton à déclencher en parametre, la fonction récupère l'id de la page courante et concatène avec l'id du control (j'ai pas réussi à faire plus simple :s).
    Ensuite, ben le bouton est déclanché.

    En fait, le postback, c'est pas très important.
    J'ai du mal à comprendre cette fonction.. Je n'arrive pas à comprendre quand la fonction va se déclencher..

  10. #10
    Membre chevronné
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2004
    Messages
    417
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Novembre 2004
    Messages : 417
    Par défaut
    En fait ce que je t'ai donné ne déclenche pas la fonction mais ajoute juste ton script a ta page.

    Et en le faisant en codeBehind ca permet plus de souplesse notamment pour passer les Id.

    Sinon pour ton probléme je te propose de faire cela dans le onload

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     TonImageButton.Attributes["onclick"] = string.Format("return ImageClicked('{0}')", tonbutton.ClientID);
    et tu ajoute ton javascript dans la les balises scripts comme au debut mais avec cette fct:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <script type="text/javascript" >
    function ImageClicked(buttonid){
          var bt = document.getElementById(buttonid);
          if (bt)
            {
             bt.click();
          }
     return false;
    }
    </script>

  11. #11
    Membre Expert Avatar de Arthis
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    1 265
    Détails du profil
    Informations personnelles :
    Âge : 48
    Localisation : Italie

    Informations forums :
    Inscription : Octobre 2003
    Messages : 1 265
    Par défaut
    Juste une petit trick pas beau mais qui pourrait aider un jour...
    au lieu de faire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <script type="text/javascript" >
    function ImageClicked(btn)
    {
        btn = "<%= UniqueID %>" + "$" + btn;
        alert(btn);
        __doPostBack(btn, '');
    }
     
    </script>
    tu deplace ton binding en dehors de la fonction javascript et la ca marche...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <script type="text/javascript" >
    
    var monID ="<%= UniqueID %>" ;
    
    function ImageClicked(btn)
    {
        btn = monID + "$" + btn;
        alert(btn);
        __doPostBack(btn, '');
    }
     
    </script>

  12. #12
    Membre chevronné
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2004
    Messages
    417
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Novembre 2004
    Messages : 417
    Par défaut
    =>Arthis
    Je comprend pas ce que ca changerais.
    Au moment du render de la valeur 'UniqueID' il s'en fiche un peu qu'il soit dans un fct javascript ou pas.
    ou sinon ca voudrais que coté serveur il ferait la différences entre les fct javascript et le reste, ca m'étonnerais non?

  13. #13
    Membre éclairé
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2007
    Messages
    375
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 375
    Par défaut
    Je pense que ca peut marcher le truc d'Arthis.
    J'ai actuellement un soucis avec mon serveur, je teste demain et je vous tiens au courant. Ca devrait le faire !

    Merci gyzmau, je savais pas comment attacher un evenement à une image en javascript.
    Et merci aussi à Arthis pr le tuyau

    Je vous dis ca demain normalement

  14. #14
    Membre chevronné
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2004
    Messages
    417
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Novembre 2004
    Messages : 417
    Par défaut
    Si ca fais une difference de le sortir de la fct javascript, je serais anéantis lol.
    Je vois pas pourquoi il arriverais a évaluer la variable en dehors de la fct javascript plutôt qu'à l'intérieur.
    Est ce que j'aurais été dans l'erreur depuis le début.
    Svp éclairer mon chemin lol.

    Merci

  15. #15
    Membre Expert Avatar de Arthis
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    1 265
    Détails du profil
    Informations personnelles :
    Âge : 48
    Localisation : Italie

    Informations forums :
    Inscription : Octobre 2003
    Messages : 1 265
    Par défaut
    Ca fonctionne en tout cas chez moi le tuyau utilisé et réutilisé...

  16. #16
    Membre éclairé
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2007
    Messages
    375
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 375
    Par défaut
    Chez moi ça ne marche pas... Pas assez long le tuyaux ?
    Je pense que c'est un problème SharePoint par contre.

    Donc j'ai pu testé avant demain, et ta solution marche très bien gyzmau, merci beaucoup.
    Je note quand même ta solution Arthis, lorsque j'arreterai le SharePoint

    Merci à vous deux
    tchao

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [OsiriX] Erreur : " **/** cannot be opened because the project file cannot be parsed"
    Par annesophie2512 dans le forum Logiciels Libres & Open Source
    Réponses: 1
    Dernier message: 12/08/2014, 14h15
  2. Réponses: 0
    Dernier message: 11/09/2009, 11h52
  3. Réponses: 3
    Dernier message: 10/08/2009, 15h14
  4. Réponses: 13
    Dernier message: 24/07/2009, 15h46
  5. Réponses: 9
    Dernier message: 19/11/2008, 08h17

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo