Yearly Archives - 2011

How to add windows forms control in WPF

I will describe how we can use windows forms controls in WPF application.I'll assume I have a WPF Application and I want to use DateTimePicker Control, how I can do that in WPF Application? 1- Create WPF Application.2- Add Stackpanel control.3- in Solution Explorer Add Reference for: System.Windows.FormsWindowsFormsIntegration using WindowsControls = System.Windows.Forms; using WindowsIntegration = System.Windows.Forms.Integration; The below method...

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack ASP.NET

While I was debugging an ASP.NET Application, I wanted to get an object values I got this error message instead: "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack" This problem occurs when using Response.Redirect or Server.Transfer method, because the Response.End method ends the page execution...

Adding the specified count to the semaphore would cause it to exceed its maximum count

I got this unusual exception while working on an ASP.NET project:"Adding the specified count to the semaphore would cause it to exceed its maximum count error". I thought it is something related to SQL Server Database Connection String.After using Query Profiler I was able to run SQL queries directly without any problems.So this means that...

How to disable some context menu items on Telerik TreeView

There is an event named "OnClientContextMenuShowing" for Rad Treeview that calls javascipt function and passes 2 arguments "sender, args".The Args parameter contains The current selected TreeNode and Context Menu Items.You can enable or disable any Context menu item based on any attributes for the Current Selected Tree Node. Here is a code snippet for the...

How to get year, month and say out of SQL Date in SQL Server

Let is say that we have the following Date 2007-04-05 10:13:14.109 and we want to get Year, Month and Day out of this date. There is a function named DATEPART() that can be used to archive this. DECLARE @MyDate AS DATETIME SET @MyDate = '2007-04-05 10:13:14.109' SELECT DATEPART(DAY, @MyDate) AS MyDay, DATEPART(MONTH, @MyDate) AS MyMonth, DATEPART(YEAR, @MyDate) AS MyYear The result...

How to avoid Uncaught ReferenceError: $ is not defined in jQuery

Sometimes while developing an existing Web Application, I wanted to use jQuery function and I got this error "Uncaught ReferenceError: $ is not defined". There are some reasons causing it and ways to avoid them: Make sure the references to the jQuery scripts is loading first, but them in the head of master page or the page you are using.Sometimes...

How to programmatically create iFrame in ASP.NET

Sometimes we may need to create iFrames and use it within GridView or Repeater, and we want to pass some values to it.This example will show you how to create iFrame Programmatically and add it to a PlaceHolder. HtmlGenericControl myFrame = new HtmlGenericControl(); myFrame.TagName = "IFRAME"; myFrame.Attributes["src"] = "MyPagePath"; myFrame.Attributes["id"] = "myFrame1"; myFrame.Attributes["name"] = "myFrame1"; myFrame.Attributes["width"] = "500"; myFrame.Attributes["height"] = "500"; myFrame.Attributes["class"] =...

Operation is not valid due to the current state of the object exception in ASP.NET

I got this error when I tried to save a Page with lots of form fields to SQL Server Database.The default max number of form fields that can be post is 1000.In order to solve this error add this Line to your Web.Config File: <appSettings> <add key="aspnet:MaxHttpCollectionKeys" value="10000" /> </appSettings>