Hi,
Sorry for my original code bit. It lacked those things that you added. I looked through your answer and the solution your provided. It was not complete as it lacked some things that weren't declared, so I couldn't run it.
The biggest difference that I could see was the RadScriptManager that you added on the .aspx page. I tried to put it in my .ascx page, but loading the page results in an error stating "Only one instance of a ScriptManager can be added to the page". Apparenlty SharePoint 2010 already has a scriptmanager running. Do I need the RadScriptManager specificly to get the RadRating rate eventhandler to work?
I'm still pretty stuck, and hoping that you can provide some assistance. Here's a more full example of my code:
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ShowQuestionsUserControl.ascx.cs" Inherits="Digia.MTVMedia.Intranet.UI.WebParts.MTVMediaShowQuestions.MTVMediaShowQuestionsUserControl" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI, Version=2010.3.1215.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" %>
<%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI.WebControls" TagPrefix="asp" %>
<%@ Register Tagprefix="SharePointPortalControls" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<SharePoint:CssRegistration ID="QAStyleCss" runat="server" Name="<% $SPUrl: ~sitecollection/Style Library/Styles/QAStyles.css %>" />
<table>
<tr>
<td valign="top" height="40">
<asp:TextBox ID="SearchBox" runat="server" CssClass="SearchBox" Width="200px"/>
<asp:ImageButton ID="SearchButton"
runat="server"
CssClass="SearchButton"
OnClick="SearchButton_Click"
ImageUrl="<% $SPUrl:~sitecollection/Style Library/Images/search_qa.png %>" />
</td>
<td valign ="top">
<a href ="#AddQ"><asp:Image ID="AddNewQBtn"
runat="server"
CssClass="SearchButton"
ImageUrl="<% $SPUrl:~sitecollection/Style Library/Images/lisaa_uusi_kysymys.png %>" /></a>
</td>
</tr>
<tr>
<td valign="top"><telerik:RadPanelBar ID="navigationByTopic" runat="server"></telerik:RadPanelBar></td>
<td valign="top">
<telerik:RadScriptManager ID="theScriptManager" runat="server" /> <!-- This causes a crash! -->
<asp:Panel ID="pnlQuestios" runat="server">
</asp:Panel>
<asp:Panel ID="pnlAnswer" runat="server" Visible="false">
</asp:Panel>
</td>
</tr>
</table>
Here's the codebehind. Basically it loads questions from a list based on the "meta" string and creates in code HTML elements to display the questions and answers.
private void loadQuestions(string meta)
{
try
{
if (meta.Length == 0) return;
//try to get list from Instructions/QA
SPList myList = SPContext.Current.Web.Lists.TryGetList("QA");
// list does not exist, then try in the root
//development enviroment QA-list is in the root, but in test enviroment QA path is different
if (myList == null)
{
SPWeb rootWeb = SPContext.Current.Site.RootWeb;
myList = rootWeb.Lists.TryGetList("QA");
}
if (myList != null)
{
var answerListItems = from SPListItem tItem in myList.Items
where tItem["Vastaus"] != null && tItem["Metatiedot"].ToString().Contains(meta) && tItem["Julkaisu"].ToString().Contains("Kyllä")
select tItem;
foreach (SPListItem answerItem in answerListItems)
{
Literal QAContent = new Literal();
RadRating QARating = new RadRating();
QAContent.Text = "<div class='qaAnswer'>";
Literal QAContentEnd = new Literal();
int intIndexQ = answerItem["Kysymys"].ToString().IndexOf('#');
if (intIndexQ != 0)
{
string question = answerItem["Kysymys"].ToString().Substring(intIndexQ + 1);
QAContent.Text += "<span class='qaStrong'>Kysymys:</span><br/>" + SPEncode.HtmlEncodePreserveSpaces(question) + "<br/><br />";
}
else
{
QAContent.Text += "<span class='qaStrong'>Kysymys:</span><br/>" + SPEncode.HtmlEncodePreserveSpaces(answerItem["Kysymys"].ToString()) + "<br/><br />";
}
if (answerItem["Vastaus"].ToString().Length >= 120)
{
QAContent.Text += "<span class='qaStrong'>Vastaus:</span><br/>" + SPEncode.HtmlEncodePreserveSpaces(answerItem["Vastaus"].ToString().Substring(0, 120)) + "... ";
LinkButton lbReadMore = new LinkButton
{
Text = " Lue lisää",
ID = answerItem.UniqueId.ToString(),
CommandName = answerItem.ID.ToString()
};
lbReadMore.Command += new CommandEventHandler(lb_Command);
lbReadMore.Click += new EventHandler(lbReadmore_Click);
pnlQuestios.Controls.Add(QAContent);
pnlQuestios.Controls.Add(lbReadMore);
}
else
{
QAContent.Text += "<span class='qaStrong'>Vastaus:</span><br/>" + SPEncode.HtmlEncodePreserveSpaces(answerItem["Vastaus"].ToString());
pnlQuestios.Controls.Add(QAContent);
}
if (answerItem["Luokitus_x0020__x0028_0_x0020__x"] != null)
{
try {
string ratingValue = answerItem["Luokitus_x0020__x0028_0_x0020__x"].ToString();
QARating.Value = Int32.Parse(ratingValue);
QARating.AutoPostBack = true;
QARating.Rate += new EventHandler(QARating_Rate);
pnlQuestios.Controls.Add(QARating);
}
catch {}
}
QAContentEnd.Text += "<br><u>" + answerItem["Editor"].ToString().Split('#')[1] + "</u>";
QAContentEnd.Text += "</div>";
pnlQuestios.Controls.Add(QAContentEnd);
}
}
pnlAnswer.Visible = false;
pnlQuestios.Visible = true;
SearchBox.Text = String.Empty;
}
catch (Exception)
{
}
}
protected void QARating_Rate(object sender, EventArgs e)
{
string foo = "foo"; // don't ever hit this while debugging...
}