locked
Problem of keeping accents between two gridview on different webpage (html - visual c#) RRS feed

  • Question

  • User-458598543 posted

    I'm looking for transmit data between two Gridview on different webpage and the accents are replaced by specials characters. How can I keep these accents in receptacle Gridview ?

    Furthermore, a click event with an other control makes an error due to this unfunctionnal conversion.

    The error is the following : [HttpRequestValidationException (0x80004005): Une valeur Request.Form potentiellement dangereuse a été détectée à partir du client (TB_ConfirmClasseJob="Animaux (élevage, promen...").]

    The code is :

    - 1st page :

           <asp:GridView ID="GV_TestFormatCaract" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1" onRowCommand="OnRowCommand" >
               <Columns>
                   <asp:BoundField DataField="T_JP_Annonce_fk_ClasseJob_Classe" HeaderText="Classe job" />
                   <asp:ButtonField ButtonType="Button" CommandName="Envoyer data" Text="Envoyer data" HeaderText="Envoyer data" />
               </Columns>
           </asp:GridView>

    __________________________________________

            protected void OnRowCommand(object sender, GridViewCommandEventArgs e)
            {
                if (e.CommandName =="Envoyer data")
                {
                    int index0 = Convert.ToInt32(e.CommandArgument);
                    string StringIndex0 = Convert.ToString(index0);

                    Session["index0Session"] = StringIndex0;

                    Server.Transfer("WebForm31.aspx");
                }

    - 2nd page :

            <asp:DropDownList ID="DDL_ClasseJob" runat="server" DataSourceID="SqlDataSource1" DataValueField="T_JP_ClasseJob_Classe"></asp:DropDownList>
            <br />
            <asp:TextBox ID="TB_ConfirmClasseJob" runat="server" width="200"></asp:TextBox>
            <br />
            <asp:Button ID="Bt_ChangerClasseJob" runat="server" Text="Changer Classe job" OnClick="ChangerClasseJob" />

    _____________________________________

            protected void Page_Load(object sender, EventArgs e)
            {
                ChargerDataGridView();
            }

            private void ChargerDataGridView()
            {
                if (Page.PreviousPage != null)
                {
           
                GV_TestFormatCaract2 = (GridView)Page.PreviousPage.FindControl("GV_TestFormatCaract");
                int index0 = Convert.ToInt32(Session["index0Session"].ToString());
                GridViewRow GVR_TestFormatCaract2 = GV_TestFormatCaract2.Rows[index0];
                TB_ConfirmClasseJob.Text = GVR_TestFormatCaract2.Cells[0].Text;
                }
            }

            protected void ChangerClasseJob(object sender, EventArgs e)
            {
                TB_ConfirmClasseJob.Text = DDL_ClasseJob.SelectedValue;
            }

    Thanks for your help !

    Wednesday, March 15, 2017 1:26 AM

Answers

  • User-271186128 posted

    Hi Rednuts72,

    How can I keep these accents in receptacle Gridview ?

    You could try to use Server.HtmlDecode() method to decoded the string before you set it to textbox.

    For example:

    TB_ConfirmClasseJob.Text = Server.HtmlDecode(GVR_TestFormatCaract2.Cells[0].Text);

    Furthermore, a click event with an other control makes an error due to this unfunctionnal conversion.

    Please try to set validateRequest property to false in page directive  to fix it.

    For example:

    <%@ Page validateRequest="false" %>

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 15, 2017 6:30 AM

All replies

  • User-271186128 posted

    Hi Rednuts72,

    How can I keep these accents in receptacle Gridview ?

    You could try to use Server.HtmlDecode() method to decoded the string before you set it to textbox.

    For example:

    TB_ConfirmClasseJob.Text = Server.HtmlDecode(GVR_TestFormatCaract2.Cells[0].Text);

    Furthermore, a click event with an other control makes an error due to this unfunctionnal conversion.

    Please try to set validateRequest property to false in page directive  to fix it.

    For example:

    <%@ Page validateRequest="false" %>

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 15, 2017 6:30 AM
  • User-1716253493 posted

    My idea is passing id (datakey) from page1 to page2

    Based the id, you can get the data in page2

    Wednesday, March 15, 2017 6:55 AM