Sunday, August 21, 2011

C# Type Casting: Prefix Vs. ‘as’ casting

Type casting in C#.
Prefix Vs. ‘as’ casting
Little bit over Boxing and unboxing.

Saturday, March 26, 2011

The Breakpoint will not currently be hit.No Symbols have been Loaded for this document


In VS 2005, you might bump into a problem where you won't be able to debug your web application.
Your break point won't hit, even if your are able to attach debugger to the worker process.
Following is a resolution for such problem
Well, i don't guarantee it will work for you. But it worked for me...



Sunday, December 26, 2010

Cross Table Queries, SQL Server Pivot

In our project we often use Cross table queries, usually for generating statistical data, or even reports.
For Pivoting.

 Pivot was introduced in SQL Server 2005.
It was a surprise to know with Microsoft Access there is a built in option to produce crosstab queries, but not so with SQL Server 2000.

Sunday, November 14, 2010

Reasons for using IDisposable: Cleaning Up Unmanaged Recourses.

About C# Disposal pattern,
How to code Disposal pattern for unmanaged resource.
Difference between Managed and Unmanaged resource.

Wednesday, November 10, 2010

Blogger trick1: Using Template Designer and increasing post Width

Using Template Designer was really cool. zero effort cool. Bu post width used to be so small that it sucked.
Tried to find solution for this problem, found several tricks to increase post width in template, none worked for new templates.
Finally i thought i should use my own head for a bit. This was simple. Then i thought why not restrict height of post and add
scroll bar so viewing multiple post on one page will be easier.
So, following things are covered in this post:
  1. Using Template designer to select template
  2. Adjusting width of layout through template designer.
  3. Adjust post width through HTML in blogger Editor.
  4. Adding scroll bar to post body by restricting height of post.
  • Goto Dashboard –> Design –> Template Designer
  • Select Template you like. Select Background.
  • In Layout tab->Body Layout –>  select layout you like, i prefer 2 column layout like this:
                   image
  • Now, Layout tab-> Adjust Width –> Select max width as 1000px, and adjust left sidebar accordingly.
image
  • Click on “Apply to Blog” button. View blog.
  • You have now created theme for blog. It’s time to increase post width or adjust max width of post.
  • Click on “Back to Blogger” link –> Edit HTML –>
  • In text Area search following text
  • <b:template-skin>
    <b:variable default='930px' name='content.width' type='length' value='1000px'/>

  • replace value=’1000px to size you want say value=’1200px’
  • Now add scroll bars to your post body:
  • Search following text in text Area
  • .post-body {
    position: relative;
    }



  • replace this block of css with following
  • .post-body {
    position: relative;
    height : 700px;
    overflow:auto;
    }



  • 700px is size i preferred you can give any height value you wish. Scroll bar will appear if your post height increases length of 700px.

Friday, October 8, 2010

Type and Search in DropDownList in ASP.NET : Using Ajax and JavaScript

  • Copy following JavaScript code and paste in <head></head> tag.
<script type = "text/javascript">
var ddlItemText //array for ddl text items
, ddlValue //array for ddl item values
, ddlSrchObj; //ddl object

//init op onload
function initItems() {
ddlItemText = new Array();
ddlValue = new Array();
ddlSrchObj = document.getElementById("<%=ddlsSrchInJS.ClientID %>");

//        Get ddl items and values onblur load
for (var i = 0; i < ddlSrchObj.options.length; i++) {
ddlItemText[ddlItemText.length] = ddlSrchObj.options[i].text;
ddlValue[ddlValue.length] = ddlSrchObj.options[i].value;
}
}
window.onload = initItems;

function SearchItem(value) {
ddlSrchObj.options.length = 0;
for (var i = 0; i < ddlItemText.length; i++) {
if (ddlItemText[i].toLowerCase().indexOf(value) != -1) {//if found
AddOption(ddlItemText[i], ddlValue[i]);
}
}
if (ddlSrchObj.options.length == 0) {//if not found
AddOption("No items found.", "");
}
}
// if found create option to show in ddl
function AddOption(text, value) {
var option = document.createElement("option");
option.text = text;
option.value = value;
ddlSrchObj.options.add(option);
}
</script>





  • Copy following line and paste it just after  <%@ Page directive.
    <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>



  • You need to add reference of Ajaxtoolkit in your webapplication if not added.
  • Copy paste following code in <form></form> tag
<table>
<tr>
<td>
Dropdown Dropdown Search using Javascript 
</td>
<td>

<asp:TextBox ID="txtSearch" runat="server"
onkeyup = "SearchItem(this.value)">
</asp:TextBox>
<br />
<asp:DropDownList ID="ddlsSrchInJS" runat="server" Height="22px" Width="157px" >
</asp:DropDownList>

</td>
</tr>
<tr>
<td >

</td>
<td >
&nbsp;</td>
</tr>
<tr>
<td>
Dropdown Search using AJAX
</td>
<td>

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:DropDownList ID="ddlAjaxSearch" runat="server" Height="22px" Width="156px">
</asp:DropDownList>
<asp:ListSearchExtender ID="ListSearchExtender1" 
TargetControlID="ddlAjaxSearch"
QueryPattern="Contains" 
runat="server">
</asp:ListSearchExtender>

</td>
</tr>
</table>
</form>

  • Following is code to add items to both dropdownlists. I’ve added 10 items and assigned values to items of dropdown to be used with javascript. In this case for dropdown to be used with ajax does not require values for items. I’ve written it on page load, you may do it in anyway you prefer.
string[] strArr = new string[10] { "vishal", "akshay", "bandya", "dilip"
, "gazala", "minal", "ninad", "kunal"
, "ajay", "rizwan" };
int i = 1;
foreach(string s in strArr)
{
ddlAjaxSearch.Items.Add((new ListItem(s)));
ddlsSrchInJS.Items.Add((new ListItem(s)));
ddlsSrchInJS.Items[ddlsSrchInJS.Items.Count - 1].Value = Convert.ToString(++i);
}

  • QueryPattern="Contains"  attribute is necessary, else by default   QueryPattern is “StartsWith”.
  • ListSearchExtender works same with ListBox too.
image image
  • Hope this helps you. Suggestions if any are welcome..

Saturday, September 18, 2010

Adding Ajax Seadragon to ASP.net aspx Page: using javaScript Part2

Before going through this post you need to check how to create and add deepzoom content and dzc/dzi file for image and add it in your VS project.
You can find how to create and add deepzoom content and dzc xml file here and here.
Now Download AjaxControlToolkit from here. And add reference of AjaxControlToolkit.dll to your project.
In your apsx page add following line to register ajax toolkit.
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="ajaxToolkit" %>




Copy paste following code inside <HTML></HTML> tag.
Change name of dsc/dzi xml file from “dzc_output.xml” to name you are using.
<head runat="server">
<style type="text/css">  
.hidden_seadragon  
{  
position: absolute;  
top: -100000px;  
display: none;  
}  
</style>  
</head>
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
<ajaxToolkit:Seadragon runat="server" ID="dummy" Width="0" Height="0" CssClass="hidden_seadragon">  
</ajaxToolkit:Seadragon>  

<div id="container" style="width: 640px; height: 480px; color: White; background-color: Black;">  
</div>  

<script type="text/javascript">  
//<![CDATA[ 
var seadragon = null; 
function init() {
seadragon = Sys.Component.create(Sys.Extended.UI.Seadragon.Viewer,
{ "controls": []
, "overlays": []
, "prefixUrl": "/"
, "xmlPath": ""
}
, null
, null
, $get("container"));
seadragon.openDzi("dzc_output.xml"); 
} 
Sys.Application.add_init(init); 

function handle(delta, Px, Py) { 
var bounds = Sys.UI.DomElement.getBounds($get("container")); 
var RegMinX = bounds.x; 
var RegMaxX = bounds.x + bounds.width; 
var RegMinY = bounds.y; 
var RegMaxY = bounds.y + bounds.height; 
if (Px >= RegMinX && Px <= RegMaxX && Py >= RegMinY && Py <= RegMaxY) { 
if (seadragon.viewport) { 
if (delta >= 0) { 
seadragon.viewport.zoomBy(seadragon.config.zoomPerClick / 1.0); 
} else if (delta < 0) { 
seadragon.viewport.zoomBy(1.0 / seadragon.config.zoomPerClick); 
} 
seadragon.viewport.applyConstraints(); 
} 
return true; 
} 
return false; 
} 

/* 
          The mouse wheel script Reference from: http://adomas.org/javascript-mouse-wheel/ 
           I just make a little modification to meet the requirement. 
        */ 
function wheel(event) { 
var delta = 0; 
if (!event) /* For IE. */ 
event = window.event; 
if (event.wheelDelta) { /* IE/Opera. */ 
delta = event.wheelDelta / 120; 
/** In Opera 9, delta differs in sign as compared to IE. 
                */ 
if (window.opera) 
delta = -delta; 
} else if (event.detail) { /** Mozilla case. */ 
/** In Mozilla, sign of delta is different than in IE. 
                * Also, delta is multiple of 3. 
                */ 
delta = -event.detail / 3; 
} 
/** If delta is nonzero, handle it. 
            * Basically, delta is now positive if wheel was scrolled up, 
            * and negative, if wheel was scrolled down. 
            */ 
if (delta) { 
var prv = handle(delta, event.x ? event.x : event.clientX, event.y ? event.y : event.clientY); 
/** Prevent default actions caused by mouse wheel. 
                * That might be ugly, but we handle scrolls somehow 
                * anyway, so don't bother here.. 
                */ 
if (prv) { 
if (event.preventDefault) 
event.preventDefault(); 
event.returnValue = false; 
} 
} 
} 
/** Initialization code.  
        * If you use your own event management code, change it as required. 
        */ 
if (window.addEventListener) 
/** DOMMouseScroll is for mozilla. */ 
window.addEventListener('DOMMouseScroll', wheel, false); 
/** IE/Opera. */ 
window.onmousewheel = document.onmousewheel = wheel; 
//]]>  
</script>  
</form>
</body>

Let me know if this has helped you. Please do share if you know better way to do the same.