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

Server Error in '/RadControlsWebSite1'

1 Answer 69 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Berlioz
Top achievements
Rank 1
Berlioz asked on 30 Nov 2011, 02:18 AM
I created a RadControlsWebSite from Visual Studio. 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
 
<head runat="server">
    <title></title>
    <link href="Styles/StyleSheet1.css" type="text/css" rel="Stylesheet"  />
            
    <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />
    <script type="text/javascript">
        function ensureSomethingSelected(source, eventargs) {
            var dropDown = $find("<%=rcb1.ClientID %>");
 
            if (dropDown.get_text() != null && dropDown.get_text() != dropDown.get_emptyMessage()) {
                args.IsValid = true;
            }
        }
     
    </script>
</head>
 
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <%--Needed for JavaScript IntelliSense in VS2010--%>
            <%--For VS2008 replace RadScriptManager with ScriptManager--%>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            
        </Scripts>
    </telerik:RadScriptManager>
     
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
     
    </telerik:RadAjaxManager>
 
 
 
<div id="cont1">
 
    <h1>SouthWinds Mfg.</h1>
    <div style="overflow:auto;">
        <asp:Label ID="lblMessage" runat="server" Text=""></asp:Label>
    </div>
    <hr />
    <div id="navButtons">
 
        <div style="float:left; width:100px;">
            <asp:Button ID="btnBack" runat="server" Text="Back" CausesValidation="false"  OnClick="btnBack_Click"/>
        </div>
 
        <div style="float:right;width:100px;">
            <asp:Button ID="btnForward" runat="server" Text="Forward" CausesValidation="false" OnClick="btnForward_Click" />
        </div>
 
    </div>
    <hr />
    <div class="class1">
        <asp:Label ID="Label1" runat="server" Text="ID" CssClass="formLabels"></asp:Label>
        <asp:Label ID="lblID" runat="server"></asp:Label>
    </div>
    <div class="class1">
    <asp:Label ID="Label2" runat="server" AssociatedControlID="txt2" Text="MFG NO" CssClass="formLabels"></asp:Label>
        <asp:TextBox ID="txt2" runat="server"></asp:TextBox>
    </div>
    <div class="class1">
    <asp:Label ID="Label3" runat="server" AssociatedControlID="txt3" Text="PART NO" CssClass="formLabels"></asp:Label>        <asp:TextBox ID="txt3" runat="server"></asp:TextBox>
    </div>
    <div class="class1">
        <asp:Label ID="Label4" runat="server" AssociatedControlID="txt4" Text="DESCR" CssClass="formLabels"></asp:Label>
     <asp:TextBox ID="txt4" runat="server"></asp:TextBox>
    </div>
    <div class="class1">If you do not see your parent, please type it in:</div>
 
    <div id="cont0">
    <telerik:RadAjaxPanel ID="rap1" runat="server">
        <telerik:RadComboBox ID="rcb1" runat="server"                
                ClientIDMode="Static"
                EnableLoadOnDemand="true"
                EnableVirtualScrolling="true"               
                ShowMoreResultsBox="true"
                OnItemsRequested="rcb1_ItemsRequested"
                Width="200" >                   
        </telerik:RadComboBox>
    </telerik:RadAjaxPanel>
    </div>
    <div style="float:none;">
        <asp:CustomValidator ID="cv1" runat="server"
            ValidateEmptyText="true"           
            ControlToValidate="rcb1"     
            EnableClientScript="true"     
            ClientValidationFunction="ensureSomethingSelected"
            ErrorMessage="You must select an item!"
            OnServerValidate="rcb1_ServerValidate">           
    </asp:CustomValidator>   
    </div>       
     <div class="buttonBar">
        <asp:Button ID="btn1" runat="server" Text="Save" OnClick="btn1_Click" />
    </form>
</body>
</html>

Here is my code-behind
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
 
public partial class Default : System.Web.UI.Page
{
 
    private const int ItemsPerRequest = 10;
 
    protected void Page_Init(object sender, EventArgs e)
    {
        
    }
     
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadPart();
        }
 
        //***RESET INFORMATION MESSAGES
        lblMessage.Text = "";
 
    }
 
    protected void btn1_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
             
        }
 
    }
 
    protected void  LoadPart()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["widConn"].ToString());
        SqlCommand cmd = new SqlCommand("SELECT * FROM PARTS", con);
 
        DataSet ds = new DataSet("dsParts");
 
        DataTable dt = new DataTable("dtParts");
 
        SqlDataAdapter da = new SqlDataAdapter(cmd);
 
        int currIndex = 0;
        ViewState["currIndex"] = currIndex;
 
        using (con)
        {
            con.Open();
 
            da.Fill(ds);
            dt = ds.Tables[0];
 
            ViewState["dtParts"] = dt;
            ViewState["rowCount"] = dt.Rows.Count;
 
            lblID.Text = Convert.ToString(dt.Rows[currIndex][0]);
            txt2.Text = (string)dt.Rows[currIndex][1];
            txt3.Text = (string)dt.Rows[currIndex][2];
            txt4.Text = Convert.ToString(dt.Rows[currIndex][3]);
        }
         
    }
 
    protected void rcb1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        
    }
 
    protected void rcb1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        DataTable data = GetData(e.Text);
 
        int itemOffset = e.NumberOfItems;
        int endOffset = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count);
        e.EndOfItems = endOffset == data.Rows.Count;
 
        for (int i = itemOffset; i < endOffset; i++)
        {
            rcb1.Items.Add(new RadComboBoxItem(data.Rows[i]["FULLY_QUALIFIED_PART_NO"].ToString(), data.Rows[i]["ID"].ToString()));
        }
 
        e.Message = GetStatusMessage(endOffset, data.Rows.Count);
    }
 
 
    private static DataTable GetData(string text)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["widConn"].ConnectionString);
 
        SqlDataAdapter adapter = new SqlDataAdapter("usp_GetMfgPartsScrolling", con);
        adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
 
        adapter.SelectCommand.Parameters.AddWithValue("@text", text);
 
        DataTable data = new DataTable();
 
        using (con)
        {
            con.Open();
            adapter.Fill(data);
        }
         
 
        return data;
    }
 
    private static string GetStatusMessage(int offset, int total)
    {
        if (total <= 0)
            return "No matches";
 
        return String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", offset, total);
    }
 
 
    protected void btnForward_Click(object sender, EventArgs e)
    {
        DataTable dt = (DataTable)ViewState["dtParts"];
 
        int currIndex = (Int32)ViewState["currIndex"];
        int rowCount = (Int32)ViewState["rowCount"];
 
        if ((currIndex  + 1) < rowCount)
        {
            lblID.Text = Convert.ToString(dt.Rows[currIndex + 1][0]);
            txt2.Text = (string)dt.Rows[currIndex + 1][1];
            txt3.Text = (string)dt.Rows[currIndex + 1][2];
 
            ViewState["currIndex"] = currIndex + 1;
        }
        else
        {
            lblMessage.Text = "You are at the end of the recordset";
        }
    }
 
    protected void btnBack_Click(object sender, EventArgs e)
    {
        DataTable dt = (DataTable)ViewState["dtParts"];
 
        int currIndex = (Int32)ViewState["currIndex"];       
 
        if (currIndex - 1 >=  0)
        {
            lblID.Text = Convert.ToString(dt.Rows[currIndex - 1][0]);
            txt2.Text = (string)dt.Rows[currIndex - 1][1];
            txt3.Text = (string)dt.Rows[currIndex - 1][2];
 
            ViewState["currIndex"] = currIndex - 1;
        }
        else
        {
            lblMessage.Text = "You are at the beginning of the recordset";
        }
    }
 
 
 
   
 
 
 
 
 
}
I get the following error message
Server Error in '/RadControlsWebSite1' Application.
--------------------------------------------------------------------------------


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

1 Answer, 1 is accepted

Sort by
0
Accepted
Ivana
Telerik team
answered on 05 Dec 2011, 09:06 AM
Hello Daniel,

This error indicates that you are using server tags ("<% %>"), within the markup. To avoid this error, you should put the script code within RadCodeBlock. More information about it could be found at the following help article at our web site: RadCodeBlock and RadScriptBlock. The error in question,  is also discussed at the following forum thread: Server tags within the markup.

I hope this helps.

All the best,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
ComboBox
Asked by
Berlioz
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Share this question
or