Monday, June 22, 2009

C# 4.0 -Optional Parameters

I was really excited, when i have seen upcoming feature in c# 4.0, After come across some article, This feature will be very useful.


Optional Parameters

Let’s say I have a class Employee and I provide few overloads of the constructor to enable making certain parameters as optional as follows:

Older Method

public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Qualification { get; set; }
public string MiddleName { get; set; }

public Employee(string firstName, string lastName)
{
FirstName= firstName;
LastName= lastName;
Qualification= "N/A";
MiddleName= string.Empty;
}
public Employee(string firstName, string lastName, string qualification)
{
FirstName= firstName;
LastName= lastName;
Qualification= qualification;
MiddleName= string.Empty;

}
public Employee(string firstName, string lastName, string qualification,
string middleName)
{
FirstName= firstName;
LastName= lastName;
Qualification= qualification;
MiddleName= middleName
}
}

Newer Method

public Employee(string firstName, string lastName,
string qualification = "N/A", string middleName = "")
{
FirstName= firstName;
LastName= lastName;
Qualification= qualification;
MiddleName = middleName;
}

Drag & Drop In Infragistics New Framework

Infragistics(2009.1), In the new version drag & drop features implemented. We can implement this feature in the html element.

Note:This is very good support for DIV element in the HTML. Dont use other thin div. when you add more functionality in the page, it may give problem when you use other than DIV.

Make sure Div elment in the outermost..

Example:

<div id="tech1"><table><tbody><tr><td></td></tr></tbody></table>
</div>


Step 1:

Download original version from Infragistics 2008 or 2009

Step 2:

Download below three files from Infragistics installed folder.

1)igDragDrop.js
2)5_igObjects.js
3)igAnimation.js

Maintain same order, when you add the Above javascript in the page.

Step 3:

Add the below script in the page, which you are going to implement the drag & drop feature.This is the script will allow the drag and drop feature.

<script type="text/javascript">
if (typeof (Sys) !== 'undefined')
{
Sys.Application.notifyScriptLoaded();
Sys.Application.add_load(appLoaded);
}
</script>

Step 4:

In the below script have two method which will enable the drag & drop for html elements.Also am adding the script in the addsource element and adddrag element.

1)addSourceElement
2)addTargetElement

It will deside the from and destination of the elements.

function appLoaded() {
ddb = new $IG.DragDropBehavior();
ddb.set_defaultDropAction($IG.DragDropAction.Insert);
ddb.set_dragDropMode($IG.DragDropEffects.Move);
var list = $get("DragUnassign");
var count = list.childNodes.length;
for (var i = 0; i <>
var child = list.childNodes[i];
if (child.getAttribute)
ddb.addSourceElement(child);
}
for (var k in techIds) {
ddb.addTargetElement($get(techIds[k]), true); //Techids nothing but a div //element of the id
var jobs = $get(techIds[k]);
if (jobs != null) {
if (jobs.childNodes != null) {
var jobCount = jobs.childNodes.length;
for (var x = 0; x <>
var job = jobs.childNodes[x];
if (job.getAttribute)
ddb.addSourceElement(job);
}
}
}
}
ddb.addTargetElement($get("DragUnassign"), true);
ddb.get_events().addDropHandler(dropHandler);
var autoComplete = $find('Auto');
}

Step 5:

In this method "$IG.DragDropBehavior()" we have method called drop Handler.

This is method it will enable the events.


Note:In the present version, It cannot write a server side method for the drag & drop feature.

Step 6:


This is the method will call the webservice.

function dropHandler(sender, args)
{
var manager = args.get_manager();
if (args.get_manager()._dragging == true) {
var progressEnable = false;
var target = manager.get_targetElement().id.replace("tech", "");
techId = target;

var obtblid = techId.replace("tech", "parent");
var sourceElement = manager.get_source().element.id;
var sourceObject = manager.get_source().element.offsetParent.id;
////////////////////This is for Dragging & droping Jobs from Unassigned to Technician////////////
if ((sourceObject == "DragUnassign") && (manager.get_targetElement().id.indexOf("tech") != -1)) {
progressEnable = true;
LTDWebApp.WebClient.WebPages.Dispatcher.TechDetails.AssignJob(target, sourceElement,drcCommitdate, "ADD", onSuccessDrag, onFailureDrag);
}
//////////////////// End for Dragging Jobs from Unassigned to Technician////////////////////////
////////////////////This is for Dragging & droping Jobs from Technician to Technician////////////
else if ((sourceObject.indexOf("tech") != -1) && (manager.get_targetElement().id.indexOf("tech") != -1)) {
progressEnable = true;
LTDWebApp.WebClient.WebPages.Dispatcher.TechDetails.AssignJob(target, sourceElement,drcCommitdate, "UPDATE", onSuccessDrag, onFailureDrag);
}
////////////////////End for Dragging & droping Jobs from Technician to Technician////////////
else
{
////////////////////This is for Dragging & droping Jobs from Technician to Unassigned ////////////
progressEnable = true;
LTDWebApp.WebClient.WebPages.Dispatcher.TechDetails.UnassignJob(sourceElement);
//LTDWebApp.WebClient.WebPages.Dispatcher.TechDetails.GetUnassignedJobs(wcgId, drcCommitdate, onSuccessDragUnassign, onFailureDrag);
////////////////////End for Dragging & droping Jobs from Technician to Unassigned////////////
}
if (progressEnable == true)
{
showProgress(techId.replace("tech", "")); ////////Showing the Progress Bar
}
}
}

Step 7:

function onSuccessDrag(Result)
{
var ddb = new $IG.DragDropBehavior();
ddb.set_defaultDropAction($IG.DragDropAction.Insert);
ddb.set_dragDropMode($IG.DragDropEffects.Move);
var obtblid = "parent"+techId;
var objTbl = document.getElementById(obtblid);
var objTbody = objTbl.getElementsByTagName("tbody")[0];
objTbl.setAttribute("cellpadding", "0");
objTbl.setAttribute("cellspacing", "0");
objTbl.setAttribute("frame", "box");
objTbl.setAttribute("className", "tblAssignParenttech");
var preRows = objTbody.rows.length;
for (j = 0; j <>
{
if (j != 0)
{
objTbody.removeChild(objTbody.rows[j]);
}
}
var objRow = document.createElement("tr");
var objTd = document.createElement("td");
var objDiv = document.createElement("div");
objRow.setAttribute("className", "tblAssignParenttechRow");
objDiv.setAttribute("className", "tblscrollAssign");
objDiv.setAttribute("id", "tech"+techId);
var len = Result.length;
for (i = 0; i <>
objSplit = Result[i].split("||");
jobId = objSplit[0];
JobInterval = objSplit[1];
JobMON = objSplit[2];
var objchildjobDiv = document.createElement("div");
objchildjobDiv.setAttribute("id", jobId);
var objchildTbl = document.createElement("table");
var objchildTblBody = document.createElement("tbody");
objchildTbl.setAttribute("border", "0");
objchildTbl.setAttribute("width", "100%");
objchildTbl.setAttribute("cellpadding", "3");
objchildTbl.setAttribute("cellspacing", "1");
objchildTbl.setAttribute("className", "liBorder");
var objchildRow = document.createElement("tr");
var objchildTd = document.createElement("td");
objchildTd.setAttribute("className", "borderstyle");
var objchildTd1 = document.createElement("td");
objchildTd.innerText = JobInterval;
objchildTd1.innerText = JobMON;
objchildRow.appendChild(objchildTd);
objchildRow.setAttribute("ondblclick", "javscript:showJob(this);");
objchildRow.appendChild(objchildTd1);
objchildTblBody.appendChild(objchildRow);
objchildTbl.appendChild(objchildTblBody);
objchildjobDiv.appendChild(objchildTbl);
objDiv.appendChild(objchildjobDiv);
ddb.addSourceElement(objchildjobDiv);
}
objTd.appendChild(objDiv);
objRow.appendChild(objTd);
objTbody.appendChild(objRow);
ddb.set_defaultDropAction($IG.DragDropAction.Insert);
ddb.addTargetElement($get("DragUnassign"), true);
ddb.addTargetElement($get("tech" + techId), true);
ddb.get_events().addDropHandler(dropHandler);
hidemodalProgress();
}


Step 8:

Once the request is succeed with above method. I am generating the client side table with array data using javascript.

function onSuccessDrag(Result)
{
var ddb = new $IG.DragDropBehavior();
ddb.set_defaultDropAction($IG.DragDropAction.Insert);
ddb.set_dragDropMode($IG.DragDropEffects.Move);
var obtblid = "parent"+techId;
var objTbl = document.getElementById(obtblid);
var objTbody = objTbl.getElementsByTagName("tbody")[0];
objTbl.setAttribute("cellpadding", "0");
objTbl.setAttribute("cellspacing", "0");
objTbl.setAttribute("frame", "box");
objTbl.setAttribute("className", "tblAssignParenttech");
var preRows = objTbody.rows.length;
for (j = 0; j <>
{
if (j != 0)
{
objTbody.removeChild(objTbody.rows[j]);
}
}
var objRow = document.createElement("tr");
var objTd = document.createElement("td");
var objDiv = document.createElement("div");
objRow.setAttribute("className", "tblAssignParenttechRow");
objDiv.setAttribute("className", "tblscrollAssign");
objDiv.setAttribute("id", "tech"+techId);
var len = Result.length;
for (i = 0; i <>
objSplit = Result[i].split("||");
jobId = objSplit[0];
JobInterval = objSplit[1];
JobMON = objSplit[2];
var objchildjobDiv = document.createElement("div");
objchildjobDiv.setAttribute("id", jobId);
var objchildTbl = document.createElement("table");
var objchildTblBody = document.createElement("tbody");
objchildTbl.setAttribute("border", "0");
objchildTbl.setAttribute("width", "100%");
objchildTbl.setAttribute("cellpadding", "3");
objchildTbl.setAttribute("cellspacing", "1");
objchildTbl.setAttribute("className", "liBorder");
var objchildRow = document.createElement("tr");
var objchildTd = document.createElement("td");
objchildTd.setAttribute("className", "borderstyle");
var objchildTd1 = document.createElement("td");
objchildTd.innerText = JobInterval;
objchildTd1.innerText = JobMON;
objchildRow.appendChild(objchildTd);
objchildRow.setAttribute("ondblclick", "javscript:showJob(this);");
objchildRow.appendChild(objchildTd1);
objchildTblBody.appendChild(objchildRow);
objchildTbl.appendChild(objchildTblBody);
objchildjobDiv.appendChild(objchildTbl);
objDiv.appendChild(objchildjobDiv);
ddb.addSourceElement(objchildjobDiv);
}
objTd.appendChild(objDiv);
objRow.appendChild(objTd);
objTbody.appendChild(objRow);
ddb.set_defaultDropAction($IG.DragDropAction.Insert);
ddb.addTargetElement($get("DragUnassign"), true);
ddb.addTargetElement($get("tech" + techId), true);
ddb.get_events().addDropHandler(dropHandler);
hidemodalProgress();
}























Tuesday, May 19, 2009

ResizableControlExtender in Ajax

Asp.Net Ajax offers a ResizableControlExtender to resize the any element in the webpages. Please follow the below steps to create the Resizablecontrolextender for the panel.

Step 1:
Create Ajax enabled website.

Step 2:

Now go to the solution explorer and add the Ajaxcontroltoolkit.dll in the root directory.

Step 3:

Also add the Ajaxcontroltoolkit.dll in the toolbox to get the control.

Step 4:

Create CSS for HandleCssClass and ResizableCssClass for the control attribute.

<style type="text/css">
.handle
{
width:10px;
height:10px;
background-color:#aaccee;
}
.resizing
{
padding:0px;
border-style:solid;
border-width:1px;
border-color:#aaccee;
cursor:se-resize;
}
</style>



Step 4:

Create one panel with the some paragraph document.

<asp:Panel ID="Panel1" runat="server" Style="width: 300px; height: 200px;">
<asp:Label ID="image1" runat="server" Text="ASP.NET AJAX offers you Resizable Extender Control. ResizableControl is an extender that attaches to any element on a web page and allows the user to resize that control with a handle that attaches to lower-right corner of the control. The resize handle lets the user resize the element as if it were a window.">
</asp:Label>
</asp:Panel>

Step 5:

Create the ResizableControlExtender and link the panel.

<cc1:resizablecontrolextender ID="ResizableControlExtender1"
runat="server" TargetControlID="Panel1" HandleCssClass="handle" ResizableCssClass="resizing" MaximumHeight="400" MaximumWidth="500"
MinimumHeight="100" MinimumWidth="100" HandleOffsetX="5" HandleOffsetY="5" />

Monday, May 18, 2009

calling WCF Service method from javascript

here am speaking about the how wcf service method will call in the clientside using javascript. please find the below examples.

Before starting the code please select the template called Ajax enabled wcf service.

then call the method in the javascript.


ASPX with javascript.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function getValue()
{
AjaxWCF.DoWork(onSucess,onFailure)
}
function onSucess(result)
{
alert(result);
}
function onFailure(result)
{
alert(result);
}
</script>
</head>
<body onload="getValue();">
<form id="form1" runat="server">
<asp:ScriptManager ID="script" runat="server">
<Services>
<asp:ServiceReference Path="~/AjaxWCF.svc" />
</Services>
</asp:ScriptManager>
</form>
</body>
</html>

AjaxWCF.svc File


using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;

namespace Xmlhttp
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class AjaxWCF
{
// Add [WebGet] attribute to use HTTP GET
[OperationContract]
public string DoWork()
{
// Add your operation implementation here
return "Hi bala";
}
// Add more operations here and mark them with [OperationContract]
}
}

Access a control on the Content Page from a MasterPage using JavaScript

If you have a control on the control page, which has to be accessed in the master page using JavaScript, then here how to do so.

on the content page. create a text box has given below.

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Panel ID="panelContent" GroupingText="ContentPage Controls" runat="server">
<asp:TextBox ID="txtContent" runat="server"></asp:TextBox>
</asp:Panel>
</asp:Content>

Now access and control the page text box "txtContent" from the master pages.

<head runat="server">
<title></title>
<script type="text/javascript">
function accessControlContentPage() {
var txtCont = document.getElementById('<%= Page.Master.FindControl("ContentPlaceHolder1").FindControl("txtContent").ClientID %>');
txtCont.value = "I got populated using Master Page";
}
</script>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>

Thursday, May 14, 2009

Calling Webservice through Ajax with javascript

In modern way of calling the web service through the JavaScript.

Aspx page

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>

<script type="text/javascript">
function OnLookup()
{
var stb = document.getElementById("txt1");
Xmlhttp.call.HelloWorld1(stb.value, OnLookupComplete);
}
function OnLookupComplete(result)
{
var res = document.getElementById("txtHint");
res.innerHTML = "<b>" + result + "</b>";
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="script" runat="server">
<Services>
<asp:ServiceReference Path="~/call.asmx" />
</Services>
</asp:ScriptManager>
First Name:<input type="text" id="txt1" onkeyup="OnLookup();">
<span id="txtHint"></span>
</div>
</form>
</body>
</html>


webservice
namespace Xmlhttp
{
///
/// Summary description for call
///

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class call : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
string value = "1";// HttpContext.Current.Request.QueryString["value"];
Dictionary objDictionary = new Dictionary();
if (HttpRuntime.Cache["out"] != null)
{
objDictionary = (Dictionary)HttpRuntime.Cache["out"];
if (!objDictionary.ContainsKey(value))
{
objDictionary.Add(value, value + "out");
}
}
else
{
objDictionary.Add(value, value + "out");
}
HttpRuntime.Cache["out"] = objDictionary;
return objDictionary[value];
}
[WebMethod]
public string HelloWorld1(string value)
{
return value;
}
}
}

Accessing webservice from javascript using XML HTTp Activex

Define:

XML http is a active X object to enable the browser to sending the request and receiving the response asynchronously.

Example:

Aspx Section


<html>
<head>
<script type="text/javascript">
var xmlHttp=null;
function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
try
{// Firefox, Opera 8.0+, Safari, IE7
xmlHttp=new XMLHttpRequest();
}
catch(e)
{// Old IE
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
alert ("Your browser does not support XMLHTTP!");
return;
}
}
var url = "http://localhost:2735/call.asmx?op=HelloWorld";
//var getValue = document.getElementById("txt1");
//url = url + "&value='" + getValue.value + "'";

xmlHttp.onreadystatechange = output;
xmlHttp.open("GET",url,true);
xmlHttp.send();
function output() {
if (xmlHttp.readyState == 4)
{
xmlHttp.open("POST", "http://localhost:2735/call.asmx/HelloWorld", false);
xmlHttp.send();
document.getElementById("txtHint").innerHTML = xmlHttp.responseText;
}
}
}
</script>
</head>
<body>
<form>
First Name:
<input type="text" id="txt1"
onkeyup="showHint(this.value)">
</form><p>Suggestions: <span id="txtHint"></span></p> </body>
</html>

Webservice Section


namespace Xmlhttp
{
///
/// Summary description for call
///

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class call : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
string value = "1";// HttpContext.Current.Request.QueryString["value"];
Dictionary objDictionary = new Dictionary();
if (HttpRuntime.Cache["out"] != null)
{
objDictionary = (Dictionary)HttpRuntime.Cache["out"];
if (!objDictionary.ContainsKey(value))
{
objDictionary.Add(value, value + "out");
}
}
else
{
objDictionary.Add(value, value + "out");
}
HttpRuntime.Cache["out"] = objDictionary;
return objDictionary[value];
}
[WebMethod]
public string HelloWorld1(string value)
{
return value;
}
}
}

Wednesday, April 15, 2009

Filtering using Linq


Filtering datarow using Linq.


object[] ArrDr = DR.ItemArray;

IList RowValue = (from filter in ArrDr where filter.ToString() != "" where filter.ToString() != " " select filter).Distinct().ToList();

Calling javscript method in different frames.

Step1:

Create one html page with following frames with frameset.

<frameset cols="30%,70%">
<frame src="testFrame.aspx" name="foody"/>
<frame src="Frame1.aspx" name="goody"/>
</frameset>

step 2:

Create one javascript method in testFrame.aspx, which it has been included in frame 1.

Javascript method.

function getValueFrame1()
{
alert("hi");
}

step 3:

call that javacript method in the second frame of page.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
<script language="javascript">
parent.foody.getValue();
</script>
</body>
</html>

Note:foody is frame name

Monday, April 13, 2009

Showing Intelligence for JavaScript methods in different Files.


Showing Intelligence for JavaScript methods in different Files.
I have created Jscript1.js with following methods with out definition.




I am referring the jscript1.js file in to script2.js using Reference Attribute. After adding the reference am getting intelligence for the jscript1.js file methods.

Tuesday, March 24, 2009

Generating javascript Id through C# (Instead of using control.clientID)

protected void Page_PreRender(object sender, EventArgs e)
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),string.Empty,string.Format("{0}"), string.Format("var gridUniqueID = '{0}'; ", uwgDailyView.UniqueID))
}

fromdate always less than todate validation using javascript

function DateCompare()
{
objfromDt="12/01/2008";
objtoDt="11/01/2008";
var arrFrom=objfromDt.value.split('/');
var arrTo=objtoDt.value.split('/');
var strFromMonth=arrFrom[0];
var strFromDate=arrFrom[1];
var strToMonth=arrTo[0];
var strToDt=arrTo[1];
if(parseInt(arrFrom[0])<10)
{
strFromMonth=arrFrom[0].replace('0','');
}
if(parseInt(arrFrom[1])<10)
{
strFromDate=arrFrom[1].replace('0','');
}
if(parseInt(arrTo[0])<10)
{
strToMonth=arrTo[0].replace('0','');
}
if(parseInt(arrTo[1])<10)
{
strToDt=arrTo[1].replace('0','');
}
var mon1 = parseInt(strFromMonth);
var dt1 = parseInt(strFromDate);
var yr1 = parseInt(arrFrom[2]);

var mon2 = parseInt(strToMonth);
var dt2 = parseInt(strToDt);
var yr2 = parseInt(arrTo[2]);

var date1 = new Date(yr1, mon1, dt1);
var date2 = new Date(yr2, mon2, dt2);
if(date2 < date1)
{
alert("From date always less than to date");
return false;
}
}

Getting Start week date for the given date

function commonformat(objDate)
{
var strdate=objDate.split("/");
var yer=strdate[2];
var da=strdate[0];
var mon=strdate[1];
var cdat=new Date(yer,mon,da);
var countDay=cdat.getDay();
if(countDay!="0")
{
cdat.setDate(cdat.getDate()-countDay);
}
return cdat;
}

Finding Eventtop and EventLeft position Using javascript

var evnt=window.event;
var y =evnt.clientY + document.body.scrollTop + document.body.parentNode.scrollTop;
var x =evnt.clientX + document.body.scrollLeft + document.body.parentNode.scrollLeft;

You have to apply this top and left position value to style attribute of the control.

Wednesday, March 18, 2009

Dependency Caching Using Oracle 11g

Dependency Caching.

It is nothing but a one of the caching mechanism for interacting with the Database.

If any data changes happen in the database,

it will find out and full out the data only on that time. It wont go every time to

the database. In this am going to explain how to do dependency caching using Oracle

11g.Also this option not avilable earlier version of oracle 11g.


Example:

In oracle11 g, there is a method called OracleDependency using this have to achieve the Oracle dependency caching.

public DataSet GetTechnicianDrpdwnval()
{
try
{
DataSet DSTechSumDrp = new DataSet();
ltdConn = new OracleConnection();
ltdConn.ConnectionString = ltdConnString;
ltdCommand = new OracleCommand("USP_GetTechSumDropdown", ltdConn);
ltdCommand.CommandType = CommandType.StoredProcedure;
ltdCommand.Parameters.Add(new OracleParameter("Drp_Primaryduty", OracleDbType.RefCursor)).Direction = ParameterDirection.Output;
ltdCommand.Parameters.Add(new OracleParameter("Drp_TypeOfWork", OracleDbType.RefCursor)).Direction = ParameterDirection.Output;
ltdCommand.Parameters.Add(new OracleParameter("Drp_DispatchCenter", OracleDbType.RefCursor)).Direction = ParameterDirection.Output;
///////////////////////////////Oracle Dependency Caching////////////////////////////////
objOracleDependency = new OracleDependency(ltdCommand);
ltdCommand.Notification.IsNotifiedOnce = false;
objOracleDependency.OnChange += new OnChangeEventHandler(ObjTechDrpDwnval);
///////////////////////////////End/////////////////////////////////////////////////////
ltdDataAdapter = new OracleDataAdapter(ltdCommand);
ltdDataAdapter.Fill(DSTechSumDrp);
return DSTechSumDrp;
}
catch (Exception)
{
throw;
}


public static void OnDatabaseNotificationForGetTechnicianDrpdwnval(object src, OracleNotificationEventArgs args)
{
// Here we have invalidate our cache object if result set changed in database.
InvalidateCache("WireCenter");
}

public static void InvalidateCache(String CacheName)
{
if (HttpRuntime.Cache[CacheName] != null)
{
HttpRuntime.Cache.Remove(CacheName);
}
}

Thursday, January 8, 2009

Typed Dataset Using Asp.net 3.5

Typed Dataset Using Asp.net 3.5

Before starting we will remember in Dotnet frame work 2.0. In this it will create only xsd and class file for that. But it will not create Adapters for retrieving dataset. We should use Sqldataadapter for getting the data. But in Asp.net 3.5 frame work it will create data adapter for that xsd. So we can get the typed dataset via adapter instead of getting from Sqldataadapter. See the step by step explanations with examples.


Step 1:

Create one employee database with table name called “contact” which has created for you. Open that database in server explorer of visual studio 2008. See picture A






Picture A

Step 2:

Create Contact.xsd file through add file option in project file. See picture B


Picture B

Step 3:

Drag and drop contact table in to the contact.xsd screen. After waiting few seconds it will create Contact.xsd file automatically. Now you can see in picture C


Picture C


Step 4

Writing few lines of code assigning this typed data values in gridview. See picture as well as the code to retrieve the typed dataset. Create one aspx page with gridview control. I am going to write the code in page load event for that page.

Example:

protected void Page_Load(object sender, EventArgs e)
{
ContactTableAdapters.ContactTableAdapter Dataadapt = new Dotnetspider.ContactTableAdapters.ContactTableAdapter();
grdlist.DataSource = Dataadapt.GetData();
grdlist.DataBind();
}

Note: ContactTableAdapter class will create automatically. This is the one main difference between frame work 2.0 and framework 3.5. But in 2.0 frame work will not create.

Happy Coding

By

Bala

Note:Images will update soon. Sorry for the inconvenience.

Monday, January 5, 2009

Using Filter Expressions with an SQL Data Source in ASP.NET VB 2008

In Visual Studio 2008, we can filter the dataset in c# with out using sqlquery.

If you use sqldatasource in your project. we can filter the dataset in c# coding itself.

Example1

If (Session("FiltExp") <> Nothing) Then
SqlDataSource1.FilterExpression = Session("FiltExp").ToString()
End If

Example2

SqlDataSource1.FilterExpression = "city='" & DropDownList1.SelectedValue & "'"

Example3

SqlDataSource1.FilterExpression = "BirthDate > #" + dt + "#"
Session("FiltExp") = "BirthDate > #" + dt + "#"

Hidden Features in C#

1) Using @ for variable that are keyword.

var @object = new object();
var @string = "";
var @if = IpsoFacto();

2) Aliased Generics.

using ASimpleName = Dictionary<string, Dictionary<string, List<string>>>;


Allows you to ASimpleName,instead of

Dictionary<string, Dictionary<string, List<string>>>;

Use it when you would use the same generic big long complex thing in a lot of places.

Thursday, January 1, 2009

Accessing server side event using Ajax 3.5 with Visual Studio 2008

Accessing server side event using Ajax 3.5 in visual studio 2008.

when we compare with earlier method,This may easy to write the code for developer.

step1 :

Include in your application system.web.extensions 3.5

Step 2:

In the script manager tag EnablePageMethods attribute make it true. it will help you to create method in the pagemethod class. Then only you can access the server event in the client side.


<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
</asp:ScriptManager>

Step 3:

We should include the namespace over the server side method.[System.Web.Services.WebMethod].

Earlier we have used [Ajax.Ajaxmethod].

Example
[System.Web.Services.WebMethod]
public static string Message(string one,string two)
{
return one + two;
}

Step 4:
Client side. while calling the server side method. it will create two default methods. if it is succeed it will call OnGetMessageSuccess, and fails it will call OnGetMessageFailure.
Example

function GetCall()
{
PageMethods.Message("122","122",OnGetMessageSuccess, OnGetMessageFailure);
}
function OnGetMessageSuccess(result,userContext,methodName)
{
alert(result);
alert(userContext);
}
function OnGetMessageFailure(error,userContext,methodName)
{
alert(error.get_message());
}

Customizing "Start Page" in Visual Studio 2010

In visual studio 2010 coming with new feature called “Start page” Customization.

This feature will be more helpful for the developers. Check the below images for your reference. Also see the comparison with visual studio 2008.


Comparision with visual studio 2008:





Step1:





Step2:





Step3:





Step4: