Skip to main content

Posts

How To Read Embedded Resource File

state.cs using System; using System.Collections.Generic; using System.Text; namespace EmbeddedResource.Library { publicclass State { privatestring _name; privatestring abbreviation; publicstring Abbreviation { get { return abbreviation; } set { abbreviation = value; } } publicstring Name { get { return _name; } set { _name = value; } } } } StatesCollection.cs using System; using System.Collections.Generic; using System.Text; using System.Xml; using System.Reflection; using System.Collections; namespace EmbeddedResource.Library { publicclass StatesCollection : System.Collections.Generic.List<State> { private StatesCollection() { } privatestatic StatesCollection _southernStates = null; publicstatic StatesCollection SouthernStates { get { if (_southernStates == null) …

Parsing Comma-Separated Values or CSV files into a DataTable using Regular Expressions

Sometimes, you find the need to parse CSV files dynamically into a DataTable. CSV files can be simple or complex. The simple CSV file would just have the fields separated by commas. Complexity comes in when the data itself has embedded commas, quotes or line breaks. This solution, written in C#, and using the .NET Framework's Regular Expression object can handle such complex data. This has been tested to work with CSV formatted files saved from Microsoft Excel. To begin with, make sure that you have the following namespaces:using System.Data; using System.IO; using System.Text.RegularExpressions; Next, we build a function that parses any CSV input string into a DataTable: publicstatic DataTable ParseCSV(string inputString) { DataTable dt = new DataTable(); // declare the Regular Expression that will match versus the input string Regex re = new Regex("((?<field>[^\",\\r\\n]+)|\"(?<field>([^\"]|\"\")+)\")(,|(?<rowbreak…

GridView UpdatePanel and Javascript

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewScript.aspx.cs" Inherits="GridViewScript" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headid="Head1"runat="server"><title>Untitled Page</title><scripttype="text/javascript">function checkCheckBoxes() { alert('There are ' + checkBoxes.length + 'checkboxes'); for(i=0;i<checkBoxes.length;i++) { var cb=document.getElementById(checkBoxes[i]); if(cb.checked) { alert('CheckBox on row ' + (i + 1) + ' is checked!' ); } } } </script></head><body><formid="form1"runat="server"><div><asp:S…

Create Dynamic Control using Repeater and List

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DynamicTextBox.aspx.cs"
Inherits="DynamicTextBox" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:TextBoxID="txtNumber"runat="server"BackColor="#FF8000"
ForeColor="#FF8000"></asp:TextBox>
<asp:ButtonID="btnCreate"runat="server"Text="Create"OnClick="btnCreate_Click"/>
<asp:RepeaterID="rpt"runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:TextBoxID="txt"runat="se…

How To Read XML Using Javascript

<%@ Page Language="C#" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<scriptrunat="server">
void Page_Load()
{
if (Request.QueryString["sendData"] != null &&
Request.QueryString["sendData"] == "ok")
{
string xml = "<book title=\"ASP.NET Code Book\" author=\"Blog\">" +
"<chapters><chapter number=\"1\" title=\"Introduction\" />" +
"<chapter number=\"2\" title=\"JavaScript\" /><chapter number=\"3\" title=\"Ajax\" />" +
"<chapter number=\"4\" title=\"WPF\" /></chapters></book>";
Response.ContentType = "text/xml";
Response.Write(xml);
Response.End();
}
}
</script>

<html xmlns="htt…

How To Join Two TextBox Values Using Javascript

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AutoName.aspx.cs" Inherits="AutoName" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headid="Head1"runat="server"><title>Untitled Page</title></head><body><formid="form1"runat="server"><div><asp:TextBoxID="firstName"runat="server"onkeyup="autoname( );"Text="First"/><asp:TextBoxID="lastName"runat="server"onkeyup="autoname( );"Text="Last"/><asp:TextBoxID="fullName"runat="server"Text=""/></div></form><scripttype="text/javascript">function autoname( ) { var temp = document.getElementById( &quo…

How To display a JavaScript alert window during a partial postback, from code behind

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxError.aspx.cs"
Inherits="AjaxError" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:ScriptManagerID="ScriptManger1"runat="server">
</asp:ScriptManager>
<asp:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:ButtonID="btnRedirect"runat="server"Text="Redirect"
OnClick="btnRedirect_Click"/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>




using System;
using System.Data;
using System.Configuration…