PC Review


Reply
Thread Tools Rate Thread

code block error on control creation

 
 
Mortar
Guest
Posts: n/a
 
      10th Aug 2005
i am dynamically creating controls when i do a server side export to
an excel file. I can only get it to work if I have no <% %> anywhere
in my html.

i.e. i am writing out session name to the html <%=Session["fname"]%>,
and when i try and do the export i get:

controls collection cannot be modified because the control contains
code blocks (i.e. <% ... %>)

how else can i write session variables or other asp variables into the
html page differently?

below is the excel export...maybe something can be changed there?

private void Button2_Click(object sender, System.EventArgs e)
{
//export to excel

Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;

System.IO.StringWriter oStringWriter = new
System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
System.Web.UI.HtmlTextWriter(oStringWriter);

// dgResults.GridLines = GridLines.None;
// dgResults.HeaderStyle.Font.Bold = true;
// dgResults.PagerStyle.BackColor =
System.Drawing.Color.White;
this.ClearControls(dgResults);
dgResults.RenderControl(oHtmlTextWriter);

Response.Write(oStringWriter.ToString());

Response.End();
}

private void ClearControls(Control control)
{
for (int i=control.Controls.Count -1; i>=0; i--)
{
ClearControls(control.Controls[i]);
}

if (!(control is TableCell))
{
if (control.GetType().GetProperty("SelectedItem") != null)
{
LiteralControl literal = new LiteralControl();
control.Parent.Controls.Add(literal);
try
{
literal.Text =
(string)control.GetType().GetProperty("SelectedItem").GetValue(control,null);
}
catch

{

}

control.Parent.Controls.Remove(control);
}

Else

if (control.GetType().GetProperty("Text") != null)
{
LiteralControl literal = new LiteralControl();
control.Parent.Controls.Add(literal);
literal.Text =
(string)control.GetType().GetProperty("Text").GetValue(control,null);
control.Parent.Controls.Remove(control);
}
}
return;
}

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
genasm.exe error finalizing the type - Control creation =?Utf-8?B?U3RyaWRlcg==?= Microsoft Dot NET Compact Framework 0 2nd Jan 2007 11:50 AM
mde creation: Produce Code compilation error if required =?Utf-8?B?Q2hpYmJ5?= Microsoft Access 3 13th Oct 2006 10:19 AM
setting error handling on control creation and deletion =?Utf-8?B?am9l?= Microsoft Excel Programming 0 22nd Feb 2006 02:35 PM
An Error Occurred During Creation of an ActiveX Control Harry Microsoft Powerpoint 1 2nd Dec 2003 09:29 AM
code block in template control Lloyd Dupont Microsoft ASP .NET 0 10th Aug 2003 04:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:14 PM.