Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i click the button that was inside the gridview it display the email inside the textbox but when i tried to select again another button to display the email on the textbox i encounter a error like this (
A potentially dangerous Request.Form value was detected from the client (txtEmailBody="...lkfkd.com)<mailto:abcdkkdlslfa...").
) can anyone help me. and this is my code.

ASP.NET
<pre> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" OnRowCommand="GridView1_RowCommand" Height="423px">
            <Columns>
                <asp:TemplateField HeaderText="Subject">
                    <ItemTemplate>
                       <asp:LinkButton OnClientClick="document.getElementById('id01').style.display='block'; return false"   runat="server" CommandArgument='<%# Eval("Subject") %>' Text='<%# Eval("Subject") %>'></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Sender" HeaderText="Receiver" />
                <asp:BoundField DataField="DateCreated" HeaderText="Date and Time Sent" />
                <asp:BoundField DataField="DateReceive" HeaderText="Date and Time Received" />
                <asp:TemplateField HeaderText="Email Body">
                    <ItemTemplate>
                       <asp:Button ID="txtItemBody"  runat="server" Text='<%# Eval("EmailHeader") %>' Width="100px" Enabled="false"/>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Get Email ">
                    <ItemTemplate>
                       <asp:Button runat="server"  CommandName="Select" CommandArgument="<%# Container.DataItemIndex %>" Text="View Email" />
                    </ItemTemplate>
                </asp:TemplateField>
                
            </Columns>
            
        </asp:GridView>
              </td>  
            <td>
               <asp:TextBox runat="server" ID="txtEmailBody" Width="650px" Height="700px" ReadOnly="true" TextMode="MultiLine" CssClass="textbox" Font-Size="Medium"></asp:TextBox>
                
            </td>


What I have tried:

and this is my code behind
C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
                if (e.CommandName == "Select")
                {

                    int rowIndex = Convert.ToInt32(e.CommandArgument);

                    //Reference the GridView Row.
                    GridViewRow row = GridView1.Rows[rowIndex];
                    //fetch the value of the body of the email
                    string EmailHeader = (row.FindControl("txtItemBody") as System.Web.UI.WebControls.Button).Text;
                    string Sender = row.Cells[2].Text;
                    txtEmailBody.Text = EmailHeader;
                
            }



C#
public void LoadResult()
        {
            
            EmailMethods email = new EmailMethods();

            email.EmailServer = "https://sampleExchangeServer.asmx";
            email.AccountName = ConfigurationManager.AppSettings["Account"];
            email.Password = ConfigurationManager.AppSettings["Secret"];
            email.Domain = ConfigurationManager.AppSettings["Domain"];
            email.GetEmails();
            DataTable dt = new DataTable();

            dt.Columns.Add("Subject", typeof(string));
            dt.Columns.Add("Sender", typeof(string));
            dt.Columns.Add("DateCreated", typeof(string));
            dt.Columns.Add("DateReceive", typeof(string));
            dt.Columns.Add("EmailHeader", typeof(string));

            foreach (Item item in email.EmailList)
            {
                dt.Rows.Add(item.Subject, item.DisplayTo, item.DateTimeCreated, item.DateTimeReceived, item.Body);

                GridView1.DataSource = dt;
                GridView1.DataBind();
                
            }

        }


C#
protected void Page_Load(object sender, EventArgs e)
       {

           if (!IsPostBack)
           {
               LoadResult();
           }
       }

and i made some research that i need to include this code
C#
<pre><system.web>
    <httpRuntime requestPathInvalidCharacters="<,>,%,&,:,\,?" />
</system.web>
and also i made some of the postback and still its not working but on the IE i click on the textbox and i hit the back space it clear the email on the textbox and i can click another button inside the gridview without an error.
Posted
Updated 28-Dec-17 5:02am
Comments
Member 13427032 28-Dec-17 10:46am    
and also it showing on the page that i need to add "Debug=true" something like this <%@ Page Language="C#" Debug="true" %> or <configuration>
<system.web>
<compilation debug="true"/>


but still its not working

1 solution

You're getting this because you're getting input that looks like it could be HTML or a URL in the textboxes. For example, if the user types in < and > symbols, those can be interpreted as possible HTML and that's not allowed unless you explicitly allow it.
 
Share this answer
 
Comments
Member 13427032 28-Dec-17 11:08am    
yes sir i check that there was a <> on the textbox. ill research on how to allow the <> on the textbox and thanks for the information.
Member 13427032 28-Dec-17 11:12am    
hi sir do you know how to allow the <> on the textbox?
thanks in advance

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900