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:

Thursday, October 30, 2008

Windows Workflow Foundation

Workflow:

Workflow is nothing but a Business Process also start with a need end with a fulfilled need.

now lets talk about Business Process.

Business Process.

Business process is a collection of activities.it will describe the start to end activity. The Business process is categrozied in to three types. The types are

1)Management Business process(Ex:Governence and Strategic Management)
2)Operation Business process(Ex:Manufactoring,Supply chain).
3)supporting Business Process(Ex:Accounting Recuriting).

Tuesday, October 14, 2008

Visual studio 2008 has a new style builder dialog

Visual studio 2008 has a new style builder dialog. For creating new style sheet, viewing the style sheet with design.Please follow the below steps to create the style sheet throgh VS tools.
step1:

step2:


step3:

Monday, August 11, 2008

Reading and writing file in Table using binary

Just follow up my steps,so that you will get clear idea.

step 1:

Create table with the folowing column, The columns are content type, filename and filedata. if you want also create some additional columns.

for "filedata" column choose datatype called "image" in the datatype list.

Note:if you choose binary datatype instead of image. unable to insert large data in to the table.

writing file in to the table

step 2:

just convert your data file to binary format, After that do insert in to table.

step 3:

how to run exe file through javascript

<html>
<head>
<script language="javascript" type="text/javascript">

function runApp()
{s
var shell = new ActiveXObject("WScript.shell");
shell.run("notepad.exe ", 1, true);
}
</script>
</head>

<body>
<input type="button" name="button1" value="Run Notepad" onClick="runApp()" />
</body>
</html>

Monday, July 7, 2008

Dropdown validation using Javascript

The below code is for validating the dropdown when click on the submit button. I have described below step by step process.

Step 1:

function getcheckdrp()
{
var drp=document.getElementById("drpcheck");
if(drp=='[object]')
{
if(drp.selectedIndex==0)
{
alert("please select state");
return false;
}
}
}

step 2:

<asp:ListItem>----Select State----</asp:ListItem>
<asp:ListItem>Karnataka</asp:ListItem>
<asp:ListItem>Bangalore</asp:ListItem>
</asp:DropDownList>

<asp:Button ID="btncheckdrp" runat="server" />

step 3:

protected void Page_Load(object sender, EventArgs e)
{
btncheckdrp.Attributes.Add("onclick", "javascript:return getcheckdrp()");
}

Tuesday, June 24, 2008

How to Register User Controls and Custom Controls in Web.config

Asp.net 2.0 makes control declarations much easier to manage.Instead of duplicating them on all your pages.just declare them once within the new pages-->controls section with in the web.config file of your application.

<?xml version="1.0"?>

<configuration>

<system.web>

<pages>
<controls>
<add tagPrefix="bala" src="~/Controls/Header.ascx" tagName="header"/>
<add tagPrefix="bala" src="~/Controls/Footer.ascx" tagName="footer"/>
<add tagPrefix="ControlVendor" assembly="ControlVendorAssembly"/>
</controls>
</pages>

</system.web>

</configuration>




<strong>Output:</strong>

<html>
<body>
<form id="form1" runat="server">
<bala:header ID="MyHeader" runat="server" />
</form>
</body>
</html>