This is a migrated thread and some comments may be shown as answers.

[Solved] Request is not available in this context Error.

1 Answer 70 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
shahid Aleem
Top achievements
Rank 1
shahid Aleem asked on 27 Feb 2010, 02:08 PM
Hello i am trying to email the radgrid but i am unable to send it.

Its giving me error when i am trying to change it into Html.

Here is my code.
public void SendPMRSetupGrid(string FromEmail, string ToEmail, string Subject, RadGrid Gridview1) 
        { 
            MailMessage MessageToSend = new MailMessage(FromEmail, ToEmail); 
            MessageToSend.IsBodyHtml = true
            MessageToSend.Subject = Subject; 
            MessageToSend.Body = GridViewToHtml(Gridview1); 
            this.Send(MessageToSend); 
        } 
        private string GridViewToHtml(RadGrid gv) 
        { 
            Page p = new Page(); 
            p.EnableEventValidation = false
            RadScriptManager ScriptManag = new RadScriptManager(); 
            HtmlForm hf = new HtmlForm(); 
            p.Controls.Add(hf); 
            hf.Controls.Add(ScriptManag); 
            hf.Controls.Add(gv); 
            StringBuilder SB = new StringBuilder(); 
            StringWriter stringWrite = new StringWriter(SB); 
            HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); 
            p.DesignerInitialize(); 
            p.RenderControl(htmlWrite); 
            p = null
            return SB.ToString(); 
        }

I am getting the Exception at p.DesignerInitialize() method saying Request is not available in this context.... When i am using the normal Gridview i have no problem at all for sending it... But when trying to radgrid its throwing this exception.

1 Answer, 1 is accepted

Sort by
0
shahid Aleem
Top achievements
Rank 1
answered on 27 Feb 2010, 03:04 PM
i got the solution....
There is no need to add Scriptmanager to the page... instead just make the

gv.RegisterWithScriptManager = false;

and it has worked.....thanks

Tags
General Discussions
Asked by
shahid Aleem
Top achievements
Rank 1
Answers by
shahid Aleem
Top achievements
Rank 1
Share this question
or