In VS 2010 there is one beautiful feature wherein you can execute your legacy applications along with your new apps. This is possible because of the multi-targeting feature available in VS 2010.
Now you can decide which .Net Framework to use for your code through VS 2010.
Just Go to Solution Explorer -> Properties -> Build -> Target Framework.
You're done with it !!!
Saturday, February 19, 2011
How to fetch value from dynamically created control
There are some cases wherein you can not create the controls to display data at compile time. For example, displaying values from a Hashtable in a TextBox control, you never know how many key-pairs you are going to deal with (provided the Hashtable contains dynamic data). The logic for displaying the data is pretty much simple. You create an array of TextBoxes or any other control to display the data and you are done with it.
But the main problem lies in fetching the data which might have got changed from the UI. If you try to find out the TextBox controls from Page.FindControl() you won't be able to do so, thats because there isn't any markup for the FindControl() to look for and thats why it will always be null.
So to tide over your problem you can simple fetch the value from just one line
Request.Form[yourcontrolID]
The Request object as we all know is base of the web architecture. So whatever is being communicated between client and a Server has to have its presence in the Request object. Technically speaking whatever controls you can find in the html markup of you page on the client side will be available in this Request object.
Happy Coding :)
But the main problem lies in fetching the data which might have got changed from the UI. If you try to find out the TextBox controls from Page.FindControl() you won't be able to do so, thats because there isn't any markup for the FindControl() to look for and thats why it will always be null.
So to tide over your problem you can simple fetch the value from just one line
Request.Form[yourcontrolID]
The Request object as we all know is base of the web architecture. So whatever is being communicated between client and a Server has to have its presence in the Request object. Technically speaking whatever controls you can find in the html markup of you page on the client side will be available in this Request object.
Happy Coding :)
Saturday, January 8, 2011
Compatibility between data types in Java and .Net
Recently I came across an interesting scenario where a Java app was consuming a .Net webservice. The challenge here was to consume a DataSet returned from a webmethod written in .Net to the calling Java UI.
One approach is to return the data in plain XML which can be done by GetXML() of the dataset but this was not acceptable. So I did a search on some similar scenarios and found out one link which lists the compatibility between different data types .. sor of a rule book you can use when you have Java UI/.Net webservice to a .Net UI/Java webservice.
http://msdn.microsoft.com/en-us/netframework/gg413252
Happy coding :)
One approach is to return the data in plain XML which can be done by GetXML() of the dataset but this was not acceptable. So I did a search on some similar scenarios and found out one link which lists the compatibility between different data types .. sor of a rule book you can use when you have Java UI/.Net webservice to a .Net UI/Java webservice.
http://msdn.microsoft.com/en-us/netframework/gg413252
Happy coding :)
Tree node event for fetching the selected node
Back after one year of CHANGE !!!
A few days ago one of my friend had a question about tree node, he wanted to copy the text of selected node else the app should not copy. So I did some R&D on events available with tree node. Its the OnSelectedNodeChanged..
Here is sample code for the same :)
*********ASPX Code****************
***************************************
*****Code behind***********
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind_tree();
}
}
public void Bind_tree()
{
DataTable dt = Get_District();
for (int i = 0; i < dt.Rows.Count; i++)
{
TreeNode no = new TreeNode();
no.Text = dt.Rows[i]["District"].ToString();
no.Value = dt.Rows[i]["District"].ToString();
Get_allNodes(no);
this.TreeView1.Nodes.Add(no);
}
}
public void Get_allNodes(TreeNode no)
{
DataTable dt = Get_Arealist();
DataRow[] rows = dt.Select("District='" + no.Value + "'");
for (int i = 0; i < rows.Length; i++)
{
TreeNode child = new TreeNode();
child.Text = rows[i]["Area"].ToString();
child.Value = rows[i]["Area"].ToString();
no.ChildNodes.Add(child);
Get_allNodes(child);
}
}
// You can get the data from your own database.
// I get the datatable like this in order to run the sample more conveniently.
public DataTable Get_District()
{
DataTable dt = new DataTable();
DataRow dr;
string Name = "District_1,District_2,District_3";
string ID = "1,2,3";
string[] list1 = Name.Split(',');
string[] list2 = ID.Split(',');
dt.Columns.Add(new DataColumn("District"));
dt.Columns.Add(new DataColumn("ID"));
for (int i = 0; i < list1.Length; i++)
{
dr = dt.NewRow();
dr["District"] = list1[i];
dr["ID"] = list2[i];
dt.Rows.Add(dr);
}
return dt;
}
// You can get the data from your own database.
// I get the datatable like this in order to run the sample more conveniently.
public DataTable Get_Arealist()
{
DataTable dt = new DataTable();
DataRow dr;
string Name = "Area_1,Area_2,Area_3,Area_4,Area_5";
string Dis = "District_1,District_1,District_1,District_3,Area_1";
string ID = "1,2,3,4,5";
string[] list1 = Name.Split(',');
string[] list2 = Dis.Split(',');
string[] list3 = ID.Split(',');
dt.Columns.Add(new DataColumn("Area"));
dt.Columns.Add(new DataColumn("District"));
dt.Columns.Add(new DataColumn("ID"));
for (int i = 0; i < list1.Length; i++)
{
dr = dt.NewRow();
dr["Area"] = list1[i];
dr["District"] = list2[i];
dr["ID"] = list3[i];
dt.Rows.Add(dr);
}
return dt;
}
protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
TreeNodeCollection ts = null;
if (e.Node.Parent == null)
{
ts = ((TreeView)sender).Nodes;
}
else
ts = e.Node.Parent.ChildNodes;
foreach (TreeNode node in ts)
{
if (node == e.Node)
{
node.Expand();
}
else
{
node.Collapse();
}
}
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
TreeNodeEventArgs xm = new TreeNodeEventArgs(this.TreeView1.SelectedNode);
TreeView1_TreeNodeExpanded(sender, xm);
string value = this.TreeView1.SelectedNode.Text;
this.Label1.Text = value;
Page.ClientScript.RegisterStartupScript(this.GetType(), "Ming", "Getvalue('" + value + "')", true);
}
Happy Coding :)
A few days ago one of my friend had a question about tree node, he wanted to copy the text of selected node else the app should not copy. So I did some R&D on events available with tree node. Its the OnSelectedNodeChanged..
Here is sample code for the same :)
*********ASPX Code****************
***************************************
*****Code behind***********
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind_tree();
}
}
public void Bind_tree()
{
DataTable dt = Get_District();
for (int i = 0; i < dt.Rows.Count; i++)
{
TreeNode no = new TreeNode();
no.Text = dt.Rows[i]["District"].ToString();
no.Value = dt.Rows[i]["District"].ToString();
Get_allNodes(no);
this.TreeView1.Nodes.Add(no);
}
}
public void Get_allNodes(TreeNode no)
{
DataTable dt = Get_Arealist();
DataRow[] rows = dt.Select("District='" + no.Value + "'");
for (int i = 0; i < rows.Length; i++)
{
TreeNode child = new TreeNode();
child.Text = rows[i]["Area"].ToString();
child.Value = rows[i]["Area"].ToString();
no.ChildNodes.Add(child);
Get_allNodes(child);
}
}
// You can get the data from your own database.
// I get the datatable like this in order to run the sample more conveniently.
public DataTable Get_District()
{
DataTable dt = new DataTable();
DataRow dr;
string Name = "District_1,District_2,District_3";
string ID = "1,2,3";
string[] list1 = Name.Split(',');
string[] list2 = ID.Split(',');
dt.Columns.Add(new DataColumn("District"));
dt.Columns.Add(new DataColumn("ID"));
for (int i = 0; i < list1.Length; i++)
{
dr = dt.NewRow();
dr["District"] = list1[i];
dr["ID"] = list2[i];
dt.Rows.Add(dr);
}
return dt;
}
// You can get the data from your own database.
// I get the datatable like this in order to run the sample more conveniently.
public DataTable Get_Arealist()
{
DataTable dt = new DataTable();
DataRow dr;
string Name = "Area_1,Area_2,Area_3,Area_4,Area_5";
string Dis = "District_1,District_1,District_1,District_3,Area_1";
string ID = "1,2,3,4,5";
string[] list1 = Name.Split(',');
string[] list2 = Dis.Split(',');
string[] list3 = ID.Split(',');
dt.Columns.Add(new DataColumn("Area"));
dt.Columns.Add(new DataColumn("District"));
dt.Columns.Add(new DataColumn("ID"));
for (int i = 0; i < list1.Length; i++)
{
dr = dt.NewRow();
dr["Area"] = list1[i];
dr["District"] = list2[i];
dr["ID"] = list3[i];
dt.Rows.Add(dr);
}
return dt;
}
protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
TreeNodeCollection ts = null;
if (e.Node.Parent == null)
{
ts = ((TreeView)sender).Nodes;
}
else
ts = e.Node.Parent.ChildNodes;
foreach (TreeNode node in ts)
{
if (node == e.Node)
{
node.Expand();
}
else
{
node.Collapse();
}
}
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
TreeNodeEventArgs xm = new TreeNodeEventArgs(this.TreeView1.SelectedNode);
TreeView1_TreeNodeExpanded(sender, xm);
string value = this.TreeView1.SelectedNode.Text;
this.Label1.Text = value;
Page.ClientScript.RegisterStartupScript(this.GetType(), "Ming", "Getvalue('" + value + "')", true);
}
Happy Coding :)
Monday, January 4, 2010
How to debug Windows service
In web apps we generally press F5 or attach the process for debugging but what to do when it comes to Windows services ???
You"ll come across docs which tell you to do loads of steps for that, but I prefer the most easy way ;)
The process of attaching debugger can be done in just ONE simple line. Use
System.Diagnostics.Debugger.Launch()
The Launch() is a static method of Debugger class. It initializes the debugger.
Now where to put this line ?? Well I prefer in the OnStart() of the Windows service which acts as a starting point of the service.
So you are all set with debugging the Windows service. Happy Debugging :)
You"ll come across docs which tell you to do loads of steps for that, but I prefer the most easy way ;)
The process of attaching debugger can be done in just ONE simple line. Use
System.Diagnostics.Debugger.Launch()
The Launch() is a static method of Debugger class. It initializes the debugger.
Now where to put this line ?? Well I prefer in the OnStart() of the Windows service which acts as a starting point of the service.
So you are all set with debugging the Windows service. Happy Debugging :)
How to disable the default progress image of Infragistics webgrid
Hi, today I faced a unique challenge and that was to disable the default progress image on the Infragistics webgrid. Now if you try to sort the column by clicking on its header you see a small image in the middle of the grid...thats the progress image am talking about.
In my case the requirement was to show a custom progress-bar image, so I had to disable the default one.
Heres what I did.
1. Call a method from the InitializeLayout() of the grid on the server-side
Eg:- e.Layout.ClientSideScript.InitializeLayoutHandler =
2. Now the method signature in this case takes two arguments by default, thats comes pre-defined from Infragistics. The first parameter is the grid-name and the second is the columnID. So if your method name is DisableImage, then its signature in the javascript file will look like this
function DisableImage(gridName, colID)
{ }
3. Now what code should I use ??? This is the most important part. Use the code below as-is and your problem is solved
var oGrid = igtbl_getGridByID(gridName);
oGrid.DisableProgressIndicator();
Wholla done !!!!
In my case the requirement was to show a custom progress-bar image, so I had to disable the default one.
Heres what I did.
1. Call a method from the InitializeLayout() of the grid on the server-side
Eg:- e.Layout.ClientSideScript.InitializeLayoutHandler =
2. Now the method signature in this case takes two arguments by default, thats comes pre-defined from Infragistics. The first parameter is the grid-name and the second is the columnID. So if your method name is DisableImage, then its signature in the javascript file will look like this
function DisableImage(gridName, colID)
{ }
3. Now what code should I use ??? This is the most important part. Use the code below as-is and your problem is solved
var oGrid = igtbl_getGridByID(gridName);
oGrid.DisableProgressIndicator();
Wholla done !!!!
Friday, December 25, 2009
How to enable connection pool in MS Access
I found out a property in the connection string with which you can enable connection pool while using MS Access as your database
Provider=Microsoft.Jet.OLEDB.4.0;OLE DB Services=-1;Datasource=Filename.mdb
The property in the red color will enable connection pooling. The reason to suggest this is it improves the performance remarkably.
Provider=Microsoft.Jet.OLEDB.
The property in the red color will enable connection pooling. The reason to suggest this is it improves the performance remarkably.
Subscribe to:
Posts (Atom)
