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

Problems in Grid Control at Web User Control

4 Answers 198 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Santhosh
Top achievements
Rank 1
Santhosh asked on 11 Mar 2009, 02:06 PM
Hi friends,

i am developing a web user control. In that i was using RadGrid latest version,
 
i am strugling with few problems like

1. I am unable to write proper java script.
2. Export to Word / Pdf not working.

when write the code like this it raise an error when the page is loading

My Code:

function

GotoNewRequestPage()

 

{

 

var obj = document.getElementById('<%= RadGridRequestLists.ClientID %>');

 

}






Error like this:
 

Server Error in '/' Application.

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
   System.Web.UI.ControlCollection.AddAt(Int32 index, Control child) +2108046
   Telerik.Web.UI.RadAjaxControl.MoveUpdatePanel(Control initiator, Control updated) +186

[HttpException (0x80004005): Please, see whether wrapping the code block, generating the exception, within RadCodeBlock resolves the error.]
   Telerik.Web.UI.RadAjaxControl.MoveUpdatePanel(Control initiator, Control updated) +244
   Telerik.Web.UI.RadAjaxControl.PerformRender() +373
   Telerik.Web.UI.RadAjaxControl.OnPageRender(HtmlTextWriter writer, Control page) +1309
   Telerik.Web.UI.RadAjaxControl.RenderPageInAjaxMode(HtmlTextWriter writer, Control page) +157
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +98
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
   System.Web.UI.Page.Render(HtmlTextWriter writer) +26
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2558


Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Mar 2009, 05:32 AM
Hello Santhosh,

To avoid these kind of exceptions you need to move the javascript code block outside of the head tag as shown in the example below:
Before:    
<head runat="server"
   <script> 
   var controlClientObject = <%= RadControl1.ClientID %> 
   ... 
   </script> 
</head> 
 
<body> 
... 
</body> 

After:    
<head runat=server> 
</head> 
<body> 
   <script> 
   var controlClientObject = <%= RadControl1.ClientID %> 
   ... 
   </script> 
... 
</body> 

You can try out the following code to export your grid on the server side:
protected void Button1_Click(object sender, EventArgs e) 
           RadGrid1.ExportSettings.IgnorePaging = true
           RadGrid1.ExportSettings.OpenInNewWindow = true
           RadGrid1.MasterTableView.ExportToExcel();   

Thanks
Princy.
0
Pavlina
Telerik team
answered on 12 Mar 2009, 07:27 AM
Hi Santhosh,

You could use RadCodeBlock in your application. The RadCodeBlock should be used when you have server code blocks placed within the markup (most often some JavaScript functions accessing server controls). It should prevents from the error you are facing. For more information on this control please review the following help topic.

More information about export to Word/Pdf is available in the following articles:
Help topic
Demo-Export to Word
Demo-Export to PDF

I hope this information helps.

Best wishes,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Santhosh
Top achievements
Rank 1
answered on 12 Mar 2009, 09:17 AM
Hi Princy,
 
1.    I was developing a web user control. In that where i can put the script code
2. Still the Export function not working.


Please remember that i was developing a web user control which i need to use into the sharepoint webpart.

Thanks in advance
0
Santhosh
Top achievements
Rank 1
answered on 12 Mar 2009, 11:15 AM
Hi Admin,


thank you Admin

'RadScriptBlock' is solved my problem.

But still i cant find my problem.

Can you anybody send me the sample which would be developed in web user control.

Thanks in advance 

Tags
Grid
Asked by
Santhosh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Pavlina
Telerik team
Santhosh
Top achievements
Rank 1
Share this question
or