TODO:
You have a RadGrid and the edit column does not show the edit button, only the "edit" text
SOLUTION:
In my case the following was in my web.config,
<add key="Telerik.EnableEmbeddedSkins" value="false"/>
so the solution was as follows.
- Add EnableEmbeddedSkins="true" to your RadGrid declaration
- Add Skin="" to your RadGrid declaration
NOTES:
TODO:
Have you ever wanted to remove a TextBox or other Control from a particular cell in a RadGrid? This is particularly useful when you want to conditionally allow edits based on certain data in the record.
SOLUTION:
protected void rgMyGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
//do it when in edit mode
if (e.Item.IsInEditMode && e.Item is GridEditableItem)
{
GridEditableItem dataItem = e.Item as GridEditableItem;
//if we have a particular type, do not allow the cell to be edited. if it is not this type, we can allow the cell to be edited
if (((Employee)dataItem.DataItem).SSN == Ssn1 ||
((Employee)dataItem.DataItem).SSN == Ssn2)
{
//we have one that needs to have name edit disabled and hidden
dataItem["Name"].Enabled = false;
dataItem["Name"].Controls[0].Visible = false;
//now create a label and add it to the controls of the "Name" cell. Set the text of the label to the text that is in the edit TextBox that we hid.
Label descLabel = new Label();
descLabel.Text = (dataItem["Name"].Controls[0] as TextBox).Text;
dataItem["Name"].Controls.Add(descLabel);
}
}
}
NOTES:
There are no notes on this topic
TODO:
You are using a Telerik RadButton, and you want to display a Confirm Dialog, and capture the user pressing cancel, thus canceling the Postback.
SOLUTION:
<!-- Define button, and put method to call in the OnClientClicking event -->
<telerik:RadButtonID="btnDelete"runat="server"Text="Delete Customer"OnClick="btnDelete_Click"
OnClientClicking="ConfirmDelete">
</telerik:RadButton>
<!-- Confirm action here. Cancel press in this dialog will return FALSE, which in turn we will catch and set cancel = true in the args -->
<telerik:RadCodeBlockID="RadCodeBlock1"runat="server">
<scripttype="text/javascript">
function ConfirmDelete(sender, args) {
if (!confirm('Delete Customer, do you wish to proceed?')) {
args.set_cancel(true);
}
}
</script>
</telerik:RadCodeBlock>
NOTES:
You may not need the RadCodeBlock, I did in this case due to Application
TODO:
Have you ever wanted to remove an image from the Header Text of a Telerik RadGrid?
SOLUTION:
/// <summary>
/// Add Header Image
/// </summary>
/// <param name="TargetGrid"></param>
/// <param name="HeaderText"></param>
protected void RemoveGridHeaderImage(RadGrid TargetGrid, string HeaderText)
{
GridHeaderItem headerItem = (GridHeaderItem)TargetGrid.MasterTableView.GetItems(GridItemType.Header)[0];
try
{
headerItem[HeaderText].Controls.AddAt(1, space);
headerItem[HeaderText].Controls.AddAt(2, img);
}
catch
{
}
}
NOTES:
All you have to do, is call this method in the PreRender() method of your RadGrid. You can use this in conjunction with adding an image to a RadGrid Header at this link, which will allow you to toggle the image on and off depending on the contents of the grid.
TODO:
Have you ever wanted to add an image to the Header Text of a Telerik RadGrid?
SOLUTION:
/// <summary>
/// Add Header Image
/// </summary>
/// <param name="TargetGrid"></param>
/// <param name="HeaderText"></param>
/// <param name="ImageUrl"></param>
protected void AddGridHeaderImage(RadGrid TargetGrid, string HeaderText, string ImageUrl)
{
GridHeaderItem headerItem = (GridHeaderItem)TargetGrid.MasterTableView.GetItems(GridItemType.Header)[0];
Image img = new Image();
Literal space = new Literal();
space.Text = " ";
try
{
img.ImageUrl = ImageUrl;
headerItem[HeaderText].Controls.AddAt(1, space);
headerItem[HeaderText].Controls.AddAt(2, img);
}
catch
{
}
finally
{
img.Dispose();
}
}
NOTES:
All you have to do, is call this method in the PreRender() method of your RadGrid.
TODO:
Have you ever wanted to add a custom filter to a RadEditor that is a EditItemTemplate in a RadGrid that lives in a RadAjaxPanel? To get this accomplished, some out of the ordinary things need to happen, or else you will end up with the dreaded 'Telerik.Web.UI.Editor' is undefined error on page load.
SOLUTION:
1. Add JavaScript to the page, that will do some things we want to happen when we go from design to html mode in the RadEditor.
<telerik:RadCodeBlock ID="rcbGirdLoaded" runat="server">
<script type="text/javascript">
function StripXSS(content) {
var newContent = content;
//Make changes to the content and return it
newContent = newContent.replace(/iframe/gi, "");
newContent = newContent.replace(/javascript:alert/gi, "");
newContent = newContent.replace(/javascript/gi, "");
//do some other stuff
return newContent;
}
function CreateRadEditorXSSFilter(editor, args) {
editor.get_filtersManager().add(new MyFilter());
}
MyFilter = function () {
MyFilter.initializeBase(this);
this.set_isDom(false);
this.set_enabled(true);
this.set_name("RadEditor XSS filter");
this.set_description("RadEditor XSS filter");
}
MyFilter.prototype =
{
getHtmlContent: function (content) {
return StripXSS(content);
},
getDesignContent: function (content) {
return StripXSS(content);
}
}
//on grid created
function AddXSSFilter()
{
MyFilter.registerClass('MyFilter', Telerik.Web.UI.Editor.Filter);
}
</script>
</telerik:RadCodeBlock>
2. Create your RadEditor, and set OnClientLoad to our function that creates the filter.
<telerik:RadEditor runat="server" ID="txtDescription" OnClientLoad="CreateRadEditorXSSFilter" RegisterWithScriptManager="false" ToolsWidth="250px" AllowScripts="false" EditModes="Design,Html" >
</telerik:RadEditor>
3. Add the client setting to the RadGrid, that will fire when a PopUp is showing (Here we add the filter)
<ClientSettings>
<ClientEvents OnPopUpShowing="AddXSSFilter" />
</ClientSettings>
NOTES:
Basically, MyFilter.registerClass('MyFilter', Telerik.Web.UI.Editor.Filter); , will cause an error on page load, because 'Telerik.Web.UI.Editor' will be undefined. We only want to execute that line, once the grid is loaded, and more so when the RadEditor is known. Since this is in AJAX, and a PopUp editor window, that line needs to happen when the client 'PopUpShowing' event is called. These code snippets show how to accomlish this.
TODO:
Have you ever wanted to remove certain files, when using RadAsyncUpload control in multi select mode? The problem is, you calling cancelUpload in the Uploading event cancels all uploads. That is not idea for obvious reasons.
SOLUTION:
var errorFiles = '';
//OnClient Uploading Event
function onClientFileUploading(sender, args) {
//if some condition is met, then cancel the upload, and add the filename to a variable.
alert('alert user possibly that file will be removed');
//cancel the upload
args.set_cancel(true);
//add to error list, we will need to remove in the Uploaded event...as it still fires.
errorFiles = errorFiles + currentUploadedFilename.toUpperCase() + '|';
}
//OnClient Uploaded Event
function onClientFileUploaded(sender, args) {
//create array of file names
var filename = errorFiles.split("|");
var count = filename.length;
//process each filename
$.each(filename.reverse(), function (key, item) {
if (args.get_fileName().toUpperCase() == item.toUpperCase()) {
//remove click
$telerik.$(".ruRemove", args.get_row()).click();
filename[key] = '';
return;
}
})
errorFiles = '';
$.each(filename.reverse(), function (key, item) {
if (item.length > 0) {
errorFiles = errorFiles + item.toUpperCase() + '|';
}
})
}
NOTES:
This snippet of code, will allow you to choose files to cancel during the upload process, and then automatically remove them from the list of documents automatically.
TODO:
Have you ever wanted to use a popup window for inserts to a Telerik RadGrid, but then allow editing to be done InPlace?
SOLUTION:
protected void rgdDocuments_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.EditCommandName)
{
rgdDocuments.MasterTableView.EditMode = GridEditMode.InPlace;
}
if (e.CommandName == RadGrid.InitInsertCommandName)
{
rgdDocuments.MasterTableView.EditMode = GridEditMode.PopUp;
}
}
NOTES:
There are no notes on this topic.
TODO:
You have a Telerik RadGrid and when you click on the Add button, you get the " Sys.ArgumentException: Value must not be null for Controls and Behaviors. Parameter name: element" error.
SOLUTION:
In my case I had the following structure:
Panel 1
FormGroup (a control we built)
Panel 2
RadGrid 1
I had AjaxSettings in my code behind for "Panel 1" and "FormGroup". Having AjaxSettings for the nested controls caused my issue. I removed the AjaxSetting for "FormGroup" and the issue went away
NOTES:
There are no notes on this topic.
TODO:
I recently had an issue, where the RadAjaxLoadingPanel would only load on the first button click. This was frustrating, and like many things Telerik, there are 10 answers and 0.5 of them work. To fix this, I hooked into the button click event in JQuery, and then showed the loading panel manually from there.
SOLUTION:
<telerik:RadCodeBlock ID="rcbInitHandler"runat="server">
<script type="text/javascript">
//global variables
var currentLoadingPanel = null;
var currentUpdatedControl = null;
//add the init activity
Sys.Application.add_init(appl_init);
//Do this on init
function appl_init() {
var pgRegMgr = Sys.WebForms.PageRequestManager.getInstance();
pgRegMgr.add_endRequest(EndHandler);
pgRegMgr.add_beginRequest(BeginHandler);
}
//Called before async postback
function BeginHandler() {
document.body.style.cursor = 'wait';
}
//Called after async postback
function EndHandler() {
if (currentLoadingPanel != null && currentUpdatedControl != null)
currentLoadingPanel.hide(currentUpdatedControl);
currentUpdatedControl = null;
currentLoadingPanel = null;
document.body.style.cursor ='default';
}
//Show the loading panel
function ShowLoadingPanel() {
currentLoadingPanel = $find('<%=rdlpLoadingPanel.ClientID%>');
currentUpdatedControl ='<%=pnlSomePanel.ClientID%>';
currentLoadingPanel.show(currentUpdatedControl);
}
$(document).ready(function () {
//Register buttons so we get pop-up. we could have done all buttons, but we do not want to get the grid button
$('#<%=btnLoad.ClientID%>').live("click",function () {
ShowLoadingPanel();
});
});
</script>
</telerik:RadCodeBlock>
NOTES:
You will need a Loading Panel called rdlLoadingPanel, a panel called pnlSomePanel, and a button called btnLoad. The rest is pretty self explanatory.