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

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top