A page can have only one server-side Form tag.

Posted by Alok under ASP.NET on 4/12/2011 | Points: 10 | Views : 36375 | Status : [Member] | Replies : 10
""A page can have only one server-side Form tag."" i m getting this error after successfully execution of code when i try to convert gridview data to word or any other format..
i have declare the function
public override void VerifyRenderingInServerForm(Control control)
{
//

}
but still getting error..
is there any code required inside this function then plz send me code..

Thanks & Regards,
Alokssm



Responses

Posted by: Prabhakar on: 4/12/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Alok

Show ur Code . . full brief . . so chek it out . .

Best Regard's
Prabhakar

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Alok on: 4/12/2011 [Member] Starter | Points: 25

Up
0
Down
protected void Button1_Click(object sender, EventArgs e)
{SmtpClient SMTP = new SmtpClient();
SMTP.Host = "smtp.gmail.com";
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.From = new MailAddress(strFrom);
message.To.Add(strTo);

message.Body = GridViewToHtml(GridView1);

message.ReplyTo = new MailAddress(strFrom);
message.Headers.Add("Reply-To", strFrom);


message.IsBodyHtml = true;
SMTP.Port = 25;

SMTP.EnableSsl = true;

SMTP.Credentials = new System.Net.NetworkCredential("abc@gmail.com", "password");
SMTP.Send(message);

}

private string GridViewToHtml(GridView gv)
{
StringBuilder sb = new StringBuilder();



System.IO.StringWriter stringWrite = new System.IO.StringWriter(sb);
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
// Create a form to contain the grid
HtmlForm frm = new HtmlForm();
GridView1.Parent.Controls.Add(frm);
// frm.Attributes["runat"] = "server";
frm.Controls.Add(GridView1);
frm.RenderControl(htmlWrite);




// gv.RenderControl(hw);
return sb.ToString();
}

public override void VerifyRenderingInServerForm(Control control)
{



}



Thanks & Regards,
Alokssm

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Alok on: 4/12/2011 [Member] Starter | Points: 25

Up
0
Down
i m waiting for reply...
Regards

Thanks & Regards,
Alokssm

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pavanandey on: 4/12/2011 [Member] Bronze | Points: 25

Up
0
Down
can you post the HTML tag info also

Thanks
Pavan Kumar
Mark Answer if this fits the need

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 4/12/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi alok . .

Sorry for let replying. . . i am just busy in work . .

i think server tag not supported two time in page . .
u check this code is this working for u . . write on button click


Response.AddHeader("content-disposition", "attachment;filename=Export.doc");

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType = "application/vnd.word";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

// Create a form to contain the grid

HtmlForm frm = new HtmlForm();

gv.Parent.Controls.Add(frm);

frm.Attributes["runat"] = "server";

frm.Controls.Add(gv);

frm.RenderControl(htmlWrite);

//GridView1.RenderControl(htw);

Response.Write(stringWrite.ToString());

Response.End();


Best Regard's
Prabhakar

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 4/12/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Alok.. .

also check this link

http://www.dotnetfunda.com/articles/article1150-all-in-one-export-data-in-aspnet-gridview-to-doc-gridview-to-excel-gr-.aspx

Best Regard's
Prabhakar

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Alok on: 4/12/2011 [Member] Starter | Points: 25

Up
0
Down
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat ="server">

<asp:Button ID="Button1" runat="server" Style="position: relative"
Text="Button" OnClick="Button1_Click" /><br />
<asp:GridView ID="GridView1" runat="server" Style="position: relative" AllowPaging="True" PageSize="3" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" Style="position: relative">show</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


</form>
</body>
</html>

Thanks & Regards,
Alokssm

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Alok on: 4/12/2011 [Member] Starter | Points: 25

Up
0
Down
Not Working..

Thanks & Regards,
Alokssm

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: NDebata on: 4/13/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Alok,

As you have a form tag in ur page ("form1"), it will not allow you add one more.

Could you please try the following.

Try you to use "form1", instead of dynamically creating a new one inside your code.
Please note that form1 contains your GridView1, So need to add it again.

Thanks,
Debata


Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 4/13/2011 [Member] Bronze | Points: 25

Up
0
Down
You are trying to duplicate the form tag. So please remove either one.

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response