Saturday, June 27, 2009

Adding, assigning and Editing the values of a data set... (.net 2.0 + )

Hello Friends, When i was working with Data Set i found some critical condition, while i have to add a new column in the existing Data Set.....
First of all you have to get a object of data column class and add your type on that class and their column name.

DataColumn dcMaxAlwdAmt = new DataColumn("MAX_ALWD_AMT", System.Type.GetType("System.Double"));
double _MaxAllowedAmtPerSch = 1000;
Then add the column in data set.
dsTranSchems.Tables[0].Columns.Add(dcMaxAlwdAmt);

Now the no is to assign the defined value at the defined position of data set....
foreach (DataRow dr in dsTranSchems.Tables[0].Rows)
{
dsTranSchems.Tables[0].Rows[_rowCount]["MAX_ALWD_AMT"] = _MaxAllowedAmtPerSch;
_rowCount = _rowCount + 1;
}


This way you can add the value by adding column and data set and add the value too.

Now i am working over Typed DataSet. Will do this soon.
Happy reading ............. Cheers Neeraj Triparthi.

Monday, June 22, 2009

Executing procedure of oracle with out parameter

This is the problem, over which i was struggling at last night. I have one oracle procedure which have two parameter on in type another of out type.

See, although we used to execute procedure like

SQL > exec proc_name(par1, par2);

But this idea failed when u have a out type parameter. So for that On SQL+ then first of all declare a variable like this

STEP 1 :

SQL> set serveroutput on;

SQL> var vartemp varchar2(150);

STEP 2 : then execute in the manner

SQL> exec MP_PROPOSAL_CODEGEN('20000585',:vartemp);

PL/SQL procedure successfully completed.

STEP 3 : And the go for the value of vaiable as

SQL> print s;

S

--------------------------------------------------------------------------------

20000585/2/062009

That is the output.

Although this is not a tough task but it's tricky. So let’s again in search of some new and good codes.

Happy coding ... Cheers Neeraj

Wednesday, May 20, 2009

Calling JavaScript on Asp.Net Code behind Page in a Ajax Enabled Site. (VS 2005 + .Net 2.0)

Hi Friends. This is interesting that you can't call a Java Script in code behind page directly as in asp.net 1.1 as ....
Let see how we do it here .... 
Suppose we have a default.aspx apge under a master page MainMaster.master then you should write down the code in the Head section of master page and call the code in the code behind page of default.aspx.cs PageLoad function as - 
Notes : in code sign <> is replaced by "

Java Script :
"script language="javascript" type="text/javascript""
function showTime()
{ alert("Hi");}
"/script"

Code Behind :
protected void Page_Load(object sender, EventArgs e)
{ScriptManager.RegisterStartupScript(this, this.GetType(), "MyCode", "showTime();", true);}

Let me in search of .....!
Cheers .. Happy programming. 
Neeraj

Monday, May 4, 2009

Implementing Ajax in VS 2003 ( .NET 1.1) by objXmlHttp java scrpit object

This is awesome to attend the code in JavaScript and it's hype more if you are playing with two different pages in asp.net.
Let see the Question is how to implement Ajax for a dropdown list in vs 2003. Then there is an idea, although it's a bit complex but it really respond spontaneously.

Note : It must works with .NET 2.0 ( VS 2005 ), and .NET 3.5 ( VS 2008 )too.

The Main Page :( .aspx page )

Now the time of implementation, we have a page (main page) having a dropdown list as ( in syntax <,> replaced by ")
"asp:dropdownlist id="DropDownList1" runat="server""
"asp:ListItem Value="--Select--""--Select--"/asp:ListItem"
"asp:ListItem Value="1""1"/asp:ListItem"
"asp:ListItem Value="2""2"/asp:ListItem"
"asp:ListItem Value="3""3"/asp:ListItem"
"/asp:dropdownlist"

and a Label as 
"asp:label id="Label1" runat="server"""/asp:label"

See we are going to select a value in dropdownlist and without postback seems in page it will immediately change the value of Label what you selected.

NOTE : Postback property of DDL is false.

Write down the Java Script, Having function for invoking the objXmlHttp
and Handling the response of XmlHttp object and show the value as required on Label

var xmlHttp;  
var requestURL = 'WebForm2.aspx?q=';  var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0;  var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0;  var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0; 
var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0; 
function getValues(strName) { if (strName.length > 0)
var str=document.getElementById("DropDownList1").value;       
var url =requestURL + str + "&qt=cl";  xmlHttp = GetXmlHttpObject(stateChangeHandler); 
xmlHttp_Get(xmlHttp, url);   }  else  { document.getElementById('Label1').innerHTML = '';  }  } 

//stateChangeHandler will fire when the state has changed, i.e. data is received back 
// This is non-blocking (asynchronous) 
function stateChangeHandler()  {  
//readyState of 4 or 'complete' represents that data has been returned 
if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){ 
//Gather the results from the callback 
var str = xmlHttp.responseText;  if (str!="nothing") {
document.getElementById("Label1").innerHTML=str; }
else { document.getElementById("Label1").value=""; } }  } 

// XMLHttp send GET request 
function xmlHttp_Get(xmlhttp, url) { xmlhttp.open('GET', url, true);  xmlhttp.send(null); } 
function GetXmlHttpObject(handler) { 
var objXmlHttp = null;    //Holds the local xmlHTTP object instance 
//Depending on the browser, try to create the xmlHttp object 
 if (is_ie) { 
//The object to create depends on version of IE 
//If it isn't ie5, then default to the Msxml2.XMLHTTP object 
var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';              
//Attempt to create the object 
try { objXmlHttp = new ActiveXObject(strObjName); objXmlHttp.onreadystatechange = handler; } 
catch(e) {  //Object creation errored 
alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');  return; } } 
else if (is_opera) { 
 //Opera has some issues with xmlHttp object functionality 
alert('Opera detected. The page may not behave as expected.'); return; } 
else {  // Mozilla | Netscape | Safari 
objXmlHttp = new XMLHttpRequest(); objXmlHttp.onload = handler; objXmlHttp.onerror = handler; } //Return the instantiated object 
 return objXmlHttp; 

Main Page Code Behind (.aspx.vb page)
Add a attribute in the dropdownlist and then register this on page load 

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
DropDownList1.Attributes.Add("onChange", "getValues('" & DropDownList1.ClientID & "');")
End Sub

Temp Page HTML : (.aspx page)
This is a temp page so no need to get any control, you may use only page directive as 

"%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb" Inherits="AjaxInVS2003API.WebForm2"%"


Temp Page Code Behind page (.aspx.vb page)

Now comeon to the code behind section of temp page... Do the job what you required 

Imports System.Xml , System.Xml.Xsl and System.Xml.XPath

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GetUsernameList()
End Sub

Private Sub GetUsernameList()
Dim strQuery As String = Request.QueryString("q")
Dim strXmlNames As String = ""
Dim sqlquery As String = ""
If (strQuery <> "--Select--") Then
strXmlNames = strQuery
Else
strXmlNames = "nothing"
End If
Response.Clear()
Response.Write(strXmlNames)
Response.End()

strXmlNames = "" & strXmlNames & ""
Dim xDoc As New XmlDocument
xDoc.LoadXml(strXmlNames)
Dim xPathNav As XPathNavigator
Dim xslt As New XslTransform
End Sub

And this works without refreshing your page will change the value of Label when you change the value of DDL. 

Happy Reading.

Let me again in search of....
Truely Your's Neeraj Tripathi. 



Tuesday, September 30, 2008

Best Practices, Create Web gardens : Enhancing performance( IIS 6.0 Web API )

To acting as bolster computing power for web site and web application, we can use a new feature there called as "Web Garden" by IIS 6.0 . This must be clear here that a web Garden can only be implemented when IIS is configured on a per application pool and running in Worker Process isolation mode.

By Implementing the
"Web Garden", we can improve availability of web application and web services, by increasing the number of worker process servicing the application pool. The idea behind configuring an application pool to use multiple worker processes (i.e a Web Garden) is to improve scalability and reliability, as these worker processes are all competing for the same CPU time.

Pleasing Benefits...
  1. Reduced resource contention : At reaching the study state of web garden, according to round robin method, every new TCP/IP connection is assigned to a worker process of web garden.
  2. Determined request processing : For request of application pool, other hunger worker processes accepts and process the request, at the time when a worker process of application pool is stop resounding.
Over criteria of...
  1. The Performance must be greater for synchronous API's.In a case if application calls a database slow responding Data Base , Then without waiting for the slow database connection to complete, Web garden supports other concurrent connections.
  2. There must be the multi-instantiated application running on, mean to different instance assigned to each worker process.
  3. Sever CPU must be best performer, mean it never be Bottleneck.
Configuring....
  1. Control Panel -> Administrative Tool -> Open IIS
  2. Right click on the Application pool. (If exits other wise create and attach the application with pool.)
  3. Go to properties -> Performance Tab - At Bottom.
  4. See -> Maximum no. of worker process (default value 1).
  5. -> Increase as required > 1.

Happy Reading.
Let me again in search of....

Neeraj Tripathi

Wednesday, August 20, 2008

Page Directive Attribute AutoEventWireup : Simple Rule and Safest Guiding

While working with asp.net, the more time I spent with this I could see deeper show of frameworks and complex logics behind.
Over looking widely, we can handle this attribute with following location --
1) At the Tag of .aspx page (For local to page only)
“%@ Page Language="C#" AutoEventWireup="true" CodeFile="AutoEvent.aspx.cs" Inherits=" AutoEvent" %”
2) By the Configuration File “web.config” (Local For An application)
"configuration""system.web""pages autoEventWireup="truefalse" /"
"/system.web""configuration"
3) For Machine with Machine Configuration File “Machine.config”
"configuration""system.web""pages autoEventWireup="truefalse" /" "/system.web""configuration"
(For An application related to machine)
4) In web usercontrol (on .ascx file)

Have a look on working style –
For VS 2005
Now for a new asp.net page by default AutoEventWirup is true, and in .aspx.cs file
The page framework calls page events automatically, specifically Page_Load and Page_Init methods.
Let a experience : We have to methods respectively
1) protected void Page_Load(object sender, EventArgs e){ }
2) protected void Button1_Click(object sender, EventArgs e) { }

When AutoEventWireup="true"
Then for every required request( Click / Refresh) of the page framework
Debuge both the 1), 2) methods. Becouse framework automatically calls the page event.
When AutoEventWireup="false"
Now see, for every required request( Click / Refresh) of the page framework Debuge only 2) methods. Becouse framework don’t calls the page event.
Now surprisengly I chip more view here as If we create the method in .aspx page as

and AutoEventWireup="true" then framework debuge only .aspx Page_Load because it hids the inharited page_load member (of .aspx.cs file).
"script runat="server" language="C#" "
protected void Page_Load(object sender, EventArgs e) { }
"/script"
I observed the signs of impending doom; I felt things where as idyllic as they appeared on the surface.

For VS 2003
In this version of .NET default AutoEventWireup="false" and now it works diffrently Here event handlers are automatically created, find this in initialize component
this.Load += new System.EventHandler(this.Page_Load);

Now If AutoEventWireup="false" and you commented the this.Load += new System.EventHandler(this.Page_Load); Then
private void Page_Load(object sender, System.EventArgs e) {}
is never calls the page event methods.

But If in this condition you set AutoEventWireup="true" then
private void Page_Load(object sender, System.EventArgs e) {}

must be called by framework. Because ASP.NET Runtime dose not require event specify event handlers, framework must make a call to CreateDelegate method for form .

And this way it happens, the massive brilliant logic having instructions as Mother of all events of a page. This is what I do and light on.

Thanks
Let again in search of …..
Cheers ….! Neeraj Tripathi.

Monday, August 18, 2008

Few words before Any More....

Courage, brother! Do not stumble, Though thy path is dark as night;
There's a star to guiding the humble--
Trust in "God" and do the right.

I express special thanks :

  • To readers of my blog and my friends. Who graciously took the time to read to me and share their views for me.
  • To Dear Shekhar Sir for your endless support and love. You are why i do what i do. I deeply value your guidance.
  • To Pankaj k Shukla for light that shows me the way and for believing in me and for making things happen.
  • And in all the way thanks to my dear seniors and colleague for wining support and action.

This is what i want to do from very first morning of my academic years, to write something for what you are witness of and whatever I can do for this humble nature and world.

Lets again in search of.....

Cheers....! Neeraj Tripathi