I am trying to use jquery ui theme (tabs) in aspx.
$(function () {
$(‘#tabs’).tabs();
});
<form id="form1" runat="server">
<div id="tabs">
<ul>
<li><a href="#tabs-1">tab 1</a></li>
<li><a href="#tabs-2">tab s2</a></li>
<li><a href="#tabs-3">tab 3</a></li>
</ul>
<div id="tabs-1">
tab-1
</div>
<div id="tabs-2">
tab-2
</div>
<div id="tabs-3">
Gridview is here
<asp:Button ID="Button2" runat="server" Height="31px" Text="Button"
onclick="Button2_Click" />
</div>
</div>
</form>
now i am calling a function button2_click doing some operation on Gridview but i am getting the error
Control ‘GridView1’ of type ‘GridView’ must be placed inside a form tag with runat=server
protected void Button2_Click(object sender, EventArgs e)
{
ExportToExcel(GridView1, "HElloWorld");
}
private void ExportToExcel(GridView gv, string filename)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=" + filename + ".xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gv.RenderControl(hw);
string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Response.Write(style);
//Response.Write(GetMessage());
Response.Output.Write(sw.ToString());
// Response.Write(GetFooter());
Response.Flush();
Response.End();
}
error is coming at gv.RenderControl(hw);
That is because you are missing one div closing tag. put
</div>just before</form>and it should work.Googling it got me this, just override the method Page.VerifyRenderingInServerForm Method, as follows:
public override void VerifyRenderingInServerForm(Control control){
return;
}
n thats it. You will be free of that error…