public void OutPut(System.Web.UI.Control ctl)  
{
string format="";
string strContentType="";
if(rbPDF.Checked) //get format selected
{
format=".pdf";
strContentType="application/pdf";
}
else if(rbExcel.Checked)
{
format=".xls";
strContentType="application/ms-excel";
}
else if(rbWord.Checked)
{
format=".doc";
strContentType="application/msword";
}

string strFileName=Request.QueryString["menuName"];
strFileName=strFileName.Replace("/","-");
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(strFileName)+format);
HttpContext.Current.Response.Charset ="UTF-8";
//HttpContext.Current.Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType =strContentType; //ms-excel/image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
ctl.Page.EnableViewState =false;
System.IO.StringWriter  tw = new System.IO.StringWriter() ;
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End(); }