Tuesday, September 23, 2008

PartialUpdatePanel Using Dotnet Framework 2.0

Contact:s.balasubramaniyam@gmail.com

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>

Monday, June 9, 2008

Accordin Control using Dotnet

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
</asp:ScriptManager>
<asp:UpdatePanel ID="updatepanel1" runat="Server">
<ContentTemplate>
<table>
<tr>
<td>dsfsd</td>
</tr>
<tr>
<td>
<cc1:Accordion ID="accordin1" runat="server" RequireOpenedPane="false">
<Panes>
<cc1:AccordionPane id="accordinpane1" runat="server">
<Header>
<asp:Label ID="lbltext" runat="server" Text="bala"></asp:Label>
</Header>
<Content>
<asp:Label ID="Label1" runat="server" Text="bala1"></asp:Label>
<cc1:Accordion ID="accordin2" runat="server" RequireOpenedPane="false">
<Panes>
<cc1:AccordionPane ID="test" runat="server">
<header>
<asp:Label ID="lbltest1" runat="server" Text="testsdfsd"></asp:Label>
</header>
<Content>
<asp:Label ID="lbltest" runat="server" Text="test"></asp:Label>
</Content>
</cc1:AccordionPane>
</Panes>
</cc1:Accordion>
</Content>

</cc1:AccordionPane>
</Panes>
</cc1:Accordion>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>

How to select all checkbox when i select header checkbox in datagrid.

<script language="javascript">
function checkall(obj)
{
var check=obj.checked;
var len=document.form1.elements.length;
for(i=0;i<len;i++)
{
if(document.form1.elements.item(i).type=="checkbox")
{
document.form1.elements.item(i).checked=check;
}
}
}
</script>
In .Aspx grid control..
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<input type="checkbox" id="head" onclick="checkall(this)"/>
</HeaderTemplate>
</asp:TemplateColumn>
</Columns>
<Columns>

number validatuion in textbox using Javascript

function typecheck(obj)
{
var check=false;
var val=obj.value;
var s=new Array("0","1","2","3","4","5","6","7","8","9");
var len=val.length;
for(i=0;i<len;i++)
{
for(j=0;j<s.length;j++)
{
if(obj.value.charAt(i)==s[j])
{
check=false
break;
}
else
{
check=true
}
}
}
if(check==true)
{
obj.value="";
obj.focus();
alert("Please type valid number");
return false;
}
}

Note:Call using onkey up event in html..

<asp:TextBox ID="txtbox" runat="server" onkeyup="javascript:return typecheck(this)" ></asp:TextBox>

how to search textbox value in dropdownlist Using Javascript

<asp:TextBox ID="txtbox" runat="server" onkeyup="getValue(this)"></asp:TextBox>
<asp:DropDownList ID="drpt" runat="server">
<asp:ListItem Text="text">ss</asp:ListItem>
<asp:ListItem Text="text">ss1</asp:ListItem>
<asp:ListItem Text="text">ss2</asp:ListItem>
<asp:ListItem Text="text">ss3</asp:ListItem>
<script language="javascript">

function getValue(obj)
{
var d=obj.value;
var dro=document.getElementById("drpt");
var drplen=document.getElementById("drpt").options.length
var i;
for(i=0;i<drplen;i++)
{
if(document.getElementById("drpt").options[i].value==d)
{
document.getElementById("drpt").selectedIndex=i;
}
}
}
</asp:DropDownList>

</script>

Sunday, June 8, 2008

Adding rows in DataGrid

DataTable dtg = (DataTable) DataGrid1.DataSource;

DataRow dr = dtg.NewRow();

dr["Item_ID"]="ItemID";
dr["Item_Name"]="Item Name";
dr["Item_Desc"]="Item Description";
dr["Item_Amount"]="$15.65";

dtg.Rows.Add(dr);

DataGrid1.DataSource = dtg;

It will work for windows.

If you use DataGrid in ASP then you will have to keep DataTable in Session:

DataTable dtg = new DataTable();

if (Session["SampleDataTable"]==null)
{

DataColumn dc;
dc = new DataColumn("Item_ID",System.Type.GetType("System.String"));
dtg.Columns.Add(dc);
dc = new DataColumn("Item_Name",System.Type.GetType("System.String"));
dtg.Columns.Add(dc);
dc = new DataColumn("Item_Desc",System.Type.GetType("System.String"));
dtg.Columns.Add(dc);
dc = new DataColumn("Item_Amount",System.Type.GetType("System.String"));
dtg.Columns.Add(dc);

}
else {dtg = (DataTable) Session["SampleDataTable"];}

DataRow dr = dtg.NewRow();
dr["Item_ID"]="ItemID";
dr["Item_Name"]="Item Name";
dr["Item_Desc"]="Item Description";
dr["Item_Amount"]="$15.35;
dtg.Rows.Add(dr);

DataGrid1.DataSource=dtg;
DataGrid1.PageSize+=1;
DataGrid1.DataBind();
Session["SampleDataTable"]=dtg;

Tuesday, June 3, 2008

Windows Communication Foundation (WCF) features

Security Features
• Facilitates interoperability through WS-* standards
• WS-Trust. Uses the secure messaging mechanisms of WS-Security
• WS-SecureConversation
• WS-Federation
• WS-SecurityPolicy
• Confidentiality – keeping messages private
• Authentication – verifying claimed identity
• Uses transport-level protocol (like HTTPS); only point-to-point secure
• Uses WS-Security; less efficient but secure from end to end
• SOAP Message Security (OASIS)

Reliable Messaging

• Provides for SOAP messages what TCP provides for IP packets
• Ensures messages are exactly once
• Handles lost messages and duplicates
• End-to-end reliability (vs. transport reliability of TCP)

Queues

• Leverages Microsoft Message Queuing (MSMQ) as a transport
• Enables loosely coupled applications and disconnected operations

Transactions

• Takes advantage of System.Transactions in .NET 2.0
• Supports WS-AtomicTransaction

Compatibility

COM+

• Extend COM+ components as Web services
• Service derived from COM+ interface

COM

• Moniker support (GetObject) for usage of WCF services from COM-based applications

Debugging the wcf Service in client side

In web.config/App.config of WCF Service have to do two changes,The details are described below

step1:
<compilation debug=true>

step2:
<servicedebug includeExceptionDetailInfaults="true"/>

Thursday, May 29, 2008

Syndication on WCF

In dotnet 3.5 has added several new things. one of those syndication. The System.ServiceModel.web has several class that you can use to expose the ATOM and RSS feed.

Restart Http Service using Command prompt

Step1: open run commmand in windows
step2: type "net start http"
step3: end

Monday, April 21, 2008

Disable Copy and Paste for greater website security

<body bgcolor="#FFFFFF" ondragstart="return false" onselectstart="return false">

Removing Xml element in two ways

<?xml version="1.0" encoding="utf-8" ?><bookstore> <books> <book genre="reference"> <title>World Atlas</title> </book> <book genre="reference"> <title>World Atlas</title> </book> </books></bookstore>


XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("test.xml"));
XmlElement root = xmldoc.DocumentElement;


root.RemoveChild(root.SelectNodes("books/book"));
root.RemoveChild(root.RemoveChild(root.FirstChild));

Replacing xml attribute in two ways

<?xml version="1.0" encoding="utf-8" ?><bookstore> <books> <book genre="reference"> <title>World Atlas</title> </book> <book genre="reference"> <title>World Atlas</title> </book> </books></bookstore>

XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("test.xml"));
XmlElement root = xmldoc.DocumentElement;
XmlNodeList nodes = root.SelectNodes("books/book");
////////////////////////////////Replaceing Attribute value using xml///////////////////////////////
foreach (XmlNode xn in nodes)
{
xn.Attributes[0].Value = "NA";
}
////////////////////////////////Replaceing Attribute value using xml///////////////////////////////
foreach (XmlNode xn1 in nodes)
{
XmlNode dd = xn1.SelectSingleNode("@genre");
}

How to get the path for "My Documents" and other system folders?

Response.write( Environment.GetFolderPath( Environment.SpecialFolder.Personal ) );

Sunday, April 20, 2008

JSON

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate
JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.
JSON is built on two structures:
1) A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
2) An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
Installation for Dotnet
http://sourceforge.net/project/showfiles.php?group_id=205597

An easy way to build connection string.

Though this in not related to .NET directly but it is useful while working with ADO.NET
1) Open a New notepad and save it with "udl" extension, suppose "New.udl".
2) Now you will see that it's icon is changed.
3) Open it, you will find Data Link properties dialog box.
4) For SQl Server connection string select Microsoft OLE DB Provider For SQL Server in Provider Tab.
5) Click button "Next" or select Connection Tab
6) Here you can select all connection details and press button
Test Connection. If it is successful close this dialog box.
7) Now open this file using "Notepad", you will find the connection string. Though it is built for OLE DB
type of connection, you can use for SQL Server connection by removing Provider attribute.
NOTE: If you are using SQL Authentication with password, then check the checkbox Allow Saving Password.
This is necessary so that password appears in connection string.