Google Brother Up

2009/02/03

Difference between a Label and a Literal in ASP.NET

1. Label is heavy weight so increases size of page while literal is light weight, so decreases size of page.
2. Label supports cssclass property but literal does not support cssclass property.
3. Label cannot be used to insert html code directly but literal can be used to insert html code directly so dynamically html tags can be created.
4. When AssociatedControl property is set, Label produces an html label as its output but when AssociatedProperty is omittedm then Label text will be wrapped in a span.

For more help refer: http://forums.asp.net/t/710459.aspx

177 unique visitors

Ad Rotator Simplest Example

1. Add two images called Microsoft.jpg, Google.jpg in images folder.

2. Create an XML page advt.xml by replacing { with <>

{?xml version="1.0" encoding="utf-8" ?}
{Advertisements}

  {Ad}
    {ImageUrl}~/images/Google.jpg{/ImageUrl}
    {NavigateUrl}http://www.google.com{/NavigateUrl}
    {AlternateText}Google{/AlternateText}
    {Impressions}1{/Impressions}
    {Keyword}Google{/Keyword}
  {/Ad}

  {Ad}
    {ImageUrl}~/images/Microsoft.jpg{/ImageUrl}
    {NavigateUrl}http://www.microsoft.com{/NavigateUrl}
    {AlternateText}Microsoft{/AlternateText}
    {Impressions}2{/Impressions}
    {Keyword}Microsoft{/Keyword}
  {/Ad}

{/Advertisements}

3. Create a Page called AdRotatorPage.aspx

{%@ Page Language="C#" AutoEventWireup="true" CodeFile="AdRotatorPage.aspx.cs" Inherits="AdRotatorPage" %}

{!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"}

{html xmlns="http://www.w3.org/1999/xhtml" }
{head runat="server"}
    {title}Ad Rotator Example{/title}
{/head}
{body}
    {form id="form1" runat="server"}
    {div}
        {asp:AdRotator ID="adrDAL" runat="server" Target="_self" AdvertisementFile="~/advt.xml"
        Height="350px" Width="500px" /}
    {/div}{br /}
    {div}
        {asp:AdRotator ID="adrDAL2" runat="server" Target="_self" AdvertisementFile="~/advt.xml"
        Height="350px" Width="500px" OnAdCreated="adrDAL2_AdCreated" /}
    {/div}
    {/form}
{/body}
{/html}

4. Create a Page called AdRotatorPage.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class AdRotatorPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void adrDAL2_AdCreated(object sender, AdCreatedEventArgs e)
    {
        e.NavigateUrl = "http://vaichatt.blogspot.com";
        //e.ImageUrl = "~/images/Yahoo.jpg"; // if this image is present there in images folder
    }
}


177 unique visitors

2008/12/19

Split a string separated by ";" and place in an array

How to split a string like this ";1;2;3;4;5;6" and put in on an array?

string mstrStream = mstrSelectedRowsStream.Remove(0,1); // to remove the semicolon on the extreme left

char chSep = ';';
string[] arrStr = mstrStream.Split(chSep);


How to get each number back from that array?

for (int i = 0; i <>
{
     string s = arrStr[i].ToString();
}

145 unique visitors

2008/12/12

Fundas on Server Paths

1. Server.MapPath(strPath)

2. (asp:Image ImageUrl=“~/images/pictures.gif runat=“server“/)

3. TextWriter tw = new StreamWriter(~"\\servername\test.txt");
tw.WriteLine("test1");
tw.Close();


4. @"C:\test\source\folder3.cs")

143 unique visitors

How to get a Path & Xml file values into a Dataset

string dtxmlFilePath = "datatypes.xml";

FileStream dtFileStream = new FileStream(Server.MapPath(dtxmlFilePath), FileMode.Open, FileAccess.Read);

StreamReader dtXmlStream = new StreamReader(dtFileStream);

ds.Tables[0].ReadXml(dtXmlStream);

dtFileStream.Close();

143 unique visitors

Convert a string to Proper Case or Sentence Case

using System.Globalization;

CultureInfo cc = new CultureInfo("");
TextInfo ti = cc.TextInfo;
ti.ToTitleCase(mlstSelectedColumn
.ColumnDataTypeCSharp)

143 unique visitors

2008/11/26

Sys.WebForms.PageRequestManagerServerErrorException:

Problem: - Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500

Solution: -

In the @Page tag set 

ValidateRequest="false"

When does it occur?

This normally occurs when there is 
1) a multiline textbox in the page
2) an update panel in the page inside which the multiline textbox resides

121 unique visitors

2008/10/31

Paging Code Behind

protected void gvColumnList_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {        
        gvColumnList.PageIndex = e.NewPageIndex;
        gvColumnList.DataSource = ViewState["vsGridView"];
        gvColumnList.DataBind();                        
    }


106 unique visitors

2008/10/27

All Databases and All Tables

  • Select All Databases from a Server (this is a system stored procedure)
sp_databases

  • Select All Tables from a Particular Database

select name from sysobjects WHERE type = 'U'

106 unique visitors

2008/09/10

A Master Page & A Content Page

A Master page defines the layout to be used by all pages based on the Master. It’s the overall parent that
controls your layout, specifying how big your header will be on every page, where your navigation features
will be placed, and the text to display in the footer on every page—a bit like a cookie cutter for
each page. The Master page contains some of the content available to each page on the site, so standard
copyright footer text can be defined here, along with positioning the main site logo at the top of the
page. After the standard features of the Master are defined, you then add some placeholders—named
regions on a page that define where content that varies from page to page will be positioned.

A Content page is a page based on a Master, and is where you add the content for each page on a site that 
varies from page to page. The Content page contains text, HTML, and controls within
tags. When the Content page is requested, its content is combined with a copy of the Master page, with
the specific content defined in the Content page placed within the specified placeholder on the Master
page. Then the whole package is delivered to the browser, as shown in Figure 2-1.

86 unique visitors

2008/09/08

Some AJAX Sites

http://en.wikipedia.org/wiki/XMLHttpRequest
http://en.wikipedia.org/wiki/AJAX
http://www.ajaxpro.info/lesson/1/
http://weblogs.asp.net/mschwarz/archive/2007/04/10/jquery-and-ajax-net-professional-ajaxpro.aspx
http://malakablog.wordpress.com/2008/07/16/using-ajax-pro-step-by-step/
http://ajaxpro.info/Examples/Special/keypress.aspx
http://weblogs.asp.net/mschwarz/default.aspx
http://dotnetslackers.com/Community/blogs/sonukapoor/archive/2007/04/19/AjaxPro-Rocks_2100_.aspx
http://www.schwarz-interactive.de/quickguide.aspx
http://www.schwarz-interactive.de/quickguide.aspx
http://munich.schwarz-interactive.de/session.aspx
http://munich.schwarz-interactive.de/autocomplete.aspx
http://ajaxpro.info/Examples/Special/keypress.aspx
http://www.schwarz-interactive.de/quickguide.aspx
http://free-ebook-download-links-gw.blogspot.com/2008/06/introducing-microsoft-aspnet-ajax-pro.html

http://ajaxpro.schwarz-interactive.de/ (good)

http://ajax.phpmagazine.net/2006/09/new_ajaxpro_java_edition.html
D:\Vaijayanta-BACKUP\Back-Up-For-XP\VAIJAYANTA\IMPORTANT\Study Materials All\Study Materials 2007 August to December\Ajax\CSharpSample
http://tricks-for-new-bloggers.blogspot.com
http://www.codeproject.com/KB/aspnet/DynamicControls.aspx
http://extjs.com/forum/archive/index.php/t-2641.html
http://extjs.com/forum/showthread.php?t=2641
http://69.10.233.10/KB/cpp/ASPNet_Ajax.aspx
http://69.10.233.10/KB/cpp/ASPNet_Ajax.aspx?fid=421153&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2483447#xx2483447xx
http://w3schools.com/html/html_forms.asp
http://news.hping.org/comp.lang.javascript.archive/17790.html
http://www.ajaxlab.com/index.php?c=AjaxProNET
http://munich.schwarz-interactive.de/default.aspx

http://www.codeproject.com/KB/ajax/AjaxValidation.aspx (good)

http://www.aspcode.net/AjaxNET-part-3.aspx (good)
http://www.codeproject.com/KB/ajax/AjaxValidation.aspx

81 unique visitors

AJAX .NET Examples and Concepts

This webpage has a lot of examples: -

http://www.asp.net/ajax/documentation/live/overview/UpdatePanelOverview.aspx

81 unique visitors

AJAX PRO Concept and Example

AJAX PRO


1. In web.config file add the tag below under (system.web) tag: -

(httpHandlers)
(add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/)
(/httpHandlers)

2. Write the TestAjaxPro.aspx file: -

(html xmlns="http://www.w3.org/1999/xhtml" )
(head runat="server")
(title)Test Ajax Pro Page(/title)

(script type="text/javascript")
function getServerTime() // being called from (body)
{
TestAjaxPro.GetServerTimeAjax(getServerTime_callback); // asynchronous call
}

function getServerTime_callback(res) // being called from inside GetServerTimeAjax() parameter
{
alert(res.value);
}
(/script)

(/head)
(body onload="javascript:getServerTime();")
(form id="form1" runat="server" )
(div)

(/div)
(/form)
(/body)
(/html)


3. Write the TestAjaxPro.aspx.cs file: -

using AjaxPro;

public partial class TestAjaxPro : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(TestAjaxPro)); //
}

[AjaxPro.AjaxMethod]
public DateTime GetServerTimeAjax() // being called from getServerTime()
{
return DateTime.Now;
}
}

4. Run the code.


81 unique visitors

2008/08/14

ConnectionString in Web.Config

(configuration)
(appSettings)
(add key="mstrConnectionString" value="user id=abcd; password=1234; server=VAIJAYANTA-PC\SQLEXPRESS; database="VaijayantaTest" /)
(/appSettings)
(/configuration)

or

(configuration)
(connectionStrings)
(add name="mstrConnectionString" connectionString="user id=abcd; password=1234 server=VAIJAYANTA-PC\SQLEXPRESS; database="VaijayantaTest" /)
(/connectionStrings)
(/configuration)

string StrCon;

StrCon = ConfigurationSettings.AppSettings.Get("mstrConnectionString");

Sqlconnection conn = new SqlConnection(StrCon );
conn.Open();
SqlCommand cmd = new SqlCommand(select,conn);

rest follows.........

72 unique visitors

2008/08/08

What is DDL, DML, DCL, TCL in SQL ?

The Data Definition Language (DDL) includes: -
CREATE TABLE - creates new database table
ALTER TABLE - alters or changes the database table
DROP TABLE - deletes the database table
CREATE INDEX - creates an index or used as a search key
DROP INDEX - deletes an index


The Data Manipulation Language (DML) includes: -
SELECT - extracts data from the database
UPDATE - updates data in the database
DELETE - deletes data from the database
INSERT INTO - inserts new data into the database

The Data Control Language (DCL) includes: -
GRANT – gives access privileges to users for database
REVOKE – withdraws access privileges to users for database

The Transaction Control Language (TCL) includes: -
COMMIT – saves the work done
ROLLBACK - restore the database to original since the last COMMIT

70 unique visitors

2008/08/05

How to write a Database Connection in Dot Net

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

source = "server=(local); integrated security=SSPI; database=Northwind";

select = "select * from Customers";
Sqlconnection conn = new SqlConnection(source);

conn.Open();

SqlCommand cmd = new SqlCommand(select,conn);

int rowsReturned = cmd.ExecuteNonQuery(); //returns no of rows affected

---------------------------
SqlDataReader reader = cmd.ExecuteReader();

while(reader.Read())

{

ConsoleWriteline(reader[0], reader[1]); //returns a set of values

} // by iterating through records

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


object o = cmd.ExecuteScalar();

Console.WriteLine(o); // returns a column

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

XmlReader xr = cmd.ExecuteXmlReader();

xr.Read(); // returns a XmlReaderObject

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

SqlDataAdapter da = new SqlDataAdapter(select, conn);

DataSet ds = new DataSet();

da.Fill(ds,"Customers"); //runtime schema generation
---------------------------------------------------------------------------

68 unique visitors

Drop Down List

1. http://www.janetsystems.co.uk/Articles/NetArticles/tabid/74/itemid/161/modid/449/Default.aspx