Wednesday, 29 February 2012

We can also add items in DropDownList/ListBox from server side.
There is one method Items.Add of DropDownList/ListBox to add items.

Example :
        Dim objListItem As ListItem
        objListItem = New ListItem("Software", 1)

        objListItem = New ListItem("Hardware", 2)

In this exaple we are adding to Items in List box from server.

There is datasource property of DropDownList/ListBox which you need to assign and after that you call DataBind method that will bind the data.

Example :
 ddlProduct.DataSource = dtDataTable

In this example we are using ddlProduct DropDownList control.
In which we are assigning DataTable as datasource. dtDataTable is a DataTable.
We can also use various datasource like collection of object , Linq object etc...

Tuesday, 28 February 2012

If you want to set default button page wise , you can use "DefaultButton" Property for Html Form Control.

Syntax :
DefaultButton="button id"

Example :
<form id="frm" DefaultButton="btnSave" runat="server">
In this when you hits the enter key the click event of btnSave button get clicked.

You can also set multipe Default button means region wise Default button in one page.
For that you use asp:Panel control.
you can use "DefaultButton" Property of asp:Panel control.

Example :
    <asp:Panel runat="server" ID="Panel1" DefaultButton="btnSave">
        <asp:TextBox runat="server" ID="txtSave"></asp:TextBox>
        <asp:Button runat="server" ID="btnSave" Text="Save"   />
    <asp:Panel runat="server" ID="pnlSearch" DefaultButton="btnSearch">
        <asp:TextBox runat="server" ID="txtSearch"></asp:TextBox>
        <asp:Button runat="server" ID="btnSearch" Text="Search"   />
In this when your cursor on txtSave textbox and you hit enter at that time btnSave button click event call,
and When your cursor on btnSearch textbox and you hit enter at that time btnSearch button click event call.

Monday, 27 February 2012

In we can also post data from one page to another page.
We can achive this through "PostBackUrl" Property of asp:Button and asp:LinkButton.
In "PostBackUrl" Property you can set the path of second page name on which you want to get posted data.

Syntax :

Example :
In First page you have like this.
 <asp:Label runat="server" ID="lblProductName" Text="Product Name :"      AssociatedControlID="txtProductName"></asp:Label>
<asp:TextBox runat="server" ID="txtProductName"></asp:TextBox>
<asp:Button runat="server" ID="btnPost" Text="Post" PostBackUrl="~/TempDefault.aspx" />
Now if we want to post Product Name on another page.You need to create public property which will return txtProductName text

The property that you need to implement in First page :
 Public ReadOnly Property GetProductName() As String
            Return txtProductName.Text
        End Get

    End Property
Now on second page you need to Register Previouse Page Type tag like this.
<%@ PreviousPageType VirtualPath="~/TestPage.aspx"%>
Here in VirtualPath property you need to set First page path from where the data will come.

Now in second page you can access First page properties like this.
Syntax :
PreviousPage.[public property]
In our example like this.

You can also create as many properties as you want for get different data.

This article is very useful for .Net Beginning.


Saturday, 25 February 2012

Getting the virtual paths local to server using this syntax.
Syntax :

If you want to use from App_Code Class or From BLL you are not allowed to use Page.ResolveURL method.
You can do this with Following syntax.
Syntax :
string url = HttpRuntime.AppDomainAppVirtualPath + "/whatever";

Note: if web application is hosted in a server root folder at that time AppDomainAppVirtualPath returns just "/". If web application is hosted in a non-root folder it returns virtual path of the folder without "/" in the end.

Friday, 24 February 2012

Following command get full SQL server version details:

Command :
    select @@VERSION

Output :
Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86)   Oct 14 2005 00:33:37   Copyright (c) 1988-2005 Microsoft Corporation  Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2)

To get specific information of server following commands:
Command :
    SELECT SERVERPROPERTY ('productversion') as product_version

Output :

Command :
    SELECT SERVERPROPERTY ('productlevel') as product_level

Output :

Command :
    SELECT SERVERPROPERTY ('edition') as edition

Output :
   Enterprise Edition

There are many cases when we need to display HTML text as HTML text without applying HTML formatting.

Syntax :

Example :
   lblProductName.Text = Server.HtmlEncode("<h1>Hi</h1>")

Output :

Without out using of HtmlEncode method It will display Formatted HTML text.
 Example :
   lblProductName.Text = "<h1>Hi</h1>"

Output :

Thursday, 23 February 2012

There is one method "length" to get length of string.


<script type="text/javascript">

     var txt="Computer";


To associate an asp:Label to From controls means , when clicking on asp:Label cursor focus move to that associate controls.

In web form there is label and text box, this label is associated with textbox so when click on label cursor focus move to text box.

<asp:Label runat="server" ID="lblProductName" Text="Product Name :" AssociatedControlID="txtProductName"></asp:Label>
<asp:TextBox runat="server" ID="txtProductName"></asp:TextBox>

Wednesday, 22 February 2012

There are various properties of Asp:Label control to set CSS formatted.

you can set like following code :

<asp:Label ID="lblmsg" runat="server" ForeColor="Red" ></asp:Label>

There is also one property name CssClass .

You can set CSS class name to this property. This will apply formatting of CSS class to label.

For write text in asp:Label , set .Text Property of Label.

From HTML View you can set like following way.
<asp:Label ID="lblProductName" runat="server" Text="TV"></asp:Label>

From Code Behind you can set like following way.
i.e : Label Id :- lblProductName code :  lblProductName.Text="TV" code :   lblProductName.Text="TV";