Monday, May 30, 2011

MS SQL Server Management Studio 2008 cannot save table change

I got this message:
Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to be re-cretead.

the solution is:
Tools > Options > Designers > Table and Database Designers
unselect 'Prevent saving changes that require the table to be re-created' check box

Wednesday, May 25, 2011

find radtextbox and hide radtextbox in javascript



var rtbName = $find("<%= rtbName.ClientID %>");
rtbName.set_value('Hello World');

Wednesday, May 11, 2011

tsql remove leading zeros in a string that is 10 characters in length

SUBSTRING([TheString], patindex('%[^0]%',[TheString]), 10)

Monday, May 02, 2011

C# get opposite colour of a given colour

public static Color FindeOppositeColor(Color InputColour)
{
return Color.FromArgb(255 - InputColour.R, 255 - InputColour.G, 255 - InputColour.B);
}

Thursday, April 14, 2011

sometimes i need to open radwindow from server side, I use this code snippet from Telerik:


protected void Button1_Click(object sender, EventArgs e)
{
Telerik.WebControls.RadWindow newwindow = new Telerik.WebControls.RadWindow();
newwindow.ID = "RadWindow1";
newwindow.NavigateUrl = "http://www.google.com";
newwindow.VisibleOnPageLoad = true;
RadWindowManager1.Windows.Add(newwindow);
}


the intellisense in Visual Studio 2010 doesn't give me "width" or "height" when i try to see if it is allowed to specifiy size for radwindow. The answer is YES, forget about the intellisense, just type it in, there you are, worked!


newwindow.Width = Unit.Pixel(500);
newwindow.Height = Unit.Pixel(500);
newwindow.Behaviors = WindowBehaviors.Move | WindowBehaviors.Close;

Wednesday, March 30, 2011

internet explorer 8 developer tools window shows in task bar but not showing

what a frustrating 5 minutes....

try Windows key + Up key

enjoy

Tuesday, March 29, 2011

move all contents from one folder to another c#

oldPath and newPath should look like "c:/FolderABC" or "~/FolderABC"


System.IO.Directory.Move(@oldPath, @newPath);

Monday, March 21, 2011

sql shrink log files

found this useful to keep necessary usage of disk space with sql db installed

USE myDatabase
GO
DBCC SHRINKFILE(myDatabase_log, 1)
BACKUP LOG myDatabase WITH TRUNCATE_ONLY
DBCC SHRINKFILE(myDatabase_log, 1)

Tuesday, March 15, 2011

radeditor doesnt open properly when first randered within a grid html edit column

found the solution at:

http://www.telerik.com/community/forums/aspnet-ajax/editor/incorrect-rendering-of-radeditor-when-shown-with-ajax-in-initially-hidden-parent.aspx

Wednesday, February 09, 2011

radgrid integer filter enter text cause error

when I enter a random text instead of an integer into the filter, and select any option in the filter options dropdown, i get error
the solution is kind of tricky:
EnableLinqExpressioins property of grid as false

Tuesday, January 11, 2011

in my radgrid i use template as EditFormType. When I open the edit form for a grid item I want to show or hide a texbos based on the value populated in it. It can be achieved this way:

Protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
{
GridEditFormItem item = (GridEditFormItem)e.Item;
TextBox TextBox1 = (TextBox)item.FindControl("TextBox1");
//OR/// TextBox txtbox = (TextBox)item["TextBox1"].Controls[0];
if (TextBox1.Text == "your value")
{
TextBox1.Visible = false;
}
}
}

Friday, January 07, 2011

radwindow pops up all the time unexpected

I use the following line in code behind to open a radwindow:




During as soon as I opened the window once, any postback will cause this window to popup again.

The solution is simple, just put the following code into page_load event.
RadWindow1.Visible = false;

Wednesday, November 17, 2010

open radwindow using radmenu item click within a template column of radgrid

first, make sure you have "ClientDataKeyNames="Id" " added into the Master Table View of the radgrid

then implement the following javascript:

function OpenRecordBreakdown(Id)
{
var oWnd = radopen("RecordBreakDown.aspx?Id=" + , "rwRecordBreakDown");
oWnd.setSize(900, 600);
oWnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Maximize + Telerik.Web.UI.WindowBehaviors.Resize + Telerik.Web.UI.WindowBehaviors.Close)
oWnd.Center();
}


var lastClickedItem = null;
var clickCalledAfterRadprompt = false;
var clickCalledAfterRadconfirm = false;
function onClientButtonClicking(sender, args) {

if (args.get_item().get_text() == "Delete") {
if (!clickCalledAfterRadconfirm) {
args.set_cancel(true);
lastClickedItem = args.get_item();
radconfirm("Are you sure you want to delete this Item?", confirmCallbackFunction);
}
}

if (args.get_item().get_text() == "Record Breakdown") {
var cell = sender.get_element().parentNode.parentNode;
rowindex = cell.rowIndex; //The row index may vary based on the grid structure.
var grid = $find("<%=rgList.ClientID %>");
var MasterTable = grid.get_masterTableView();
var id = MasterTable.get_dataItems()[rowindex - 2].getDataKeyValue("Id");

OpenRecordBreakdown(id);

args.set_cancel(true);
}
}

function confirmCallbackFunction(args) {
if (args) {
clickCalledAfterRadconfirm = true;
lastClickedItem.click();
}
else
clickCalledAfterRadconfirm = false;
lastClickedItem = null;
}

Thursday, November 11, 2010

Using radprompt and radconfirm with Telerik navigational controls

Found this article very useful, hope it can help you as well

Using radprompt and radconfirm with Telerik navigational controls

http://www.telerik.com/support/kb/aspnet-ajax/window/using-radprompt-and-radconfirm-with-telerik-navigational-controls.aspx

Wednesday, November 10, 2010

open radwindow in codebehind by radcombobox selectedindexchanged event

ScriptManager.RegisterStartupScript(this, typeof(abc_def_1), "openWin", "openWin('" + ParameterId.ToString() + "');", true);

provide you still need the radwindow manager in .aspx code, and the javascript "openWin"

Monday, October 18, 2010

Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEve

"Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation."

in my case it is caused by trying to call a radgrid.rebind() in page_load, the radgrid sits inside of a radupdatepanel. In case of postback the code contains client script which caused this security breach. After I put radgrid.rebind() inside !IsPostBack the error disappearred.

Thursday, September 09, 2010

Persist RadGrid Settings

found this class really helpful:
http://www.telerik.com/help/aspnet-ajax/grdsavingsettingsonperuserbasis.html

Tuesday, August 03, 2010

Friday, July 16, 2010

visual studio 2010 issue referencing usercontrol property from container page

When I tried to reference a public property in user control from a container page, the intellisense doesn't seem to be able to pick up the property. Ignore the red curly underline, build the parent page, it worked~

another VS2010 bug?