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.
<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
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[rowIndex];
string EmailHeader = (row.FindControl("txtItemBody") as System.Web.UI.WebControls.Button).Text;
string Sender = row.Cells[2].Text;
txtEmailBody.Text = EmailHeader;
}
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();
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadResult();
}
}
and i made some research that i need to include this code
<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.