button click event on master page

H

hazz

oh it hurts to be a newbie again....:-(

I have a button click event I want to handle for a button to create an excel
spreadsheet from gridview contents.
I can't write the code for the button click event on the master cuz it
doesn't know anything about Gridview1.

But if I put the code on the page where GridView1 is and NOT on the
masterpage, then I get this;
Error 1 'ASP.masterpage_master' does not contain a definition for
'Button1_Click' \test_report\MasterPage.master 38

But the tutorials made this all look so easy !!

Thanks,
-Greg
 
H

hazz

public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.PreviousPage != null)
{
GridView SourceGridView =
(GridView)Page.PreviousPage.FindControl("GridView1");
if (SourceGridView != null)
{
//what do I do here; I need to call a button click event
on the page GridView1 is on as per below. ???????
}
}
}

protected void BtnExport_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename=FileName.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
btnExport code courtesy of Mohammad Azam at http://aspalliance.com/771
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top