Monday, August 11, 2008

ASP.NET BASIC


ASP.NET is a web application framework developed and marketed by Microsoft, that programmers can use to build dynamic web sites, web applications and web services. It was first released in January 2002 with version 1.0 of the .NET Framework, and is the successor to Microsoft's Active Server (ASP) technology. ASP.NET is built on the Common Language Runtime (CLR), allowing programmers to write ASP.NET code using any supported .NET language.






FIRSTLY I WOULD LIKE TO MENTION THE

Advantages of ASP.NET

  1. Separation of Code from HTML
    To make a clean sweep, with ASP.NET you have the ability to completely separate layout and business logic. This makes it much easier for teams of programmers and designers to collaborate efficiently. This makes it much easier for teams of programmers and designers to collaborate efficiently.

  2. Support for compiled languages
    developer can use VB.NET and access features such as strong typing and object-oriented programming. Using compiled languages also means that ASP.NET pages do not suffer the performance penalties associated with interpreted code. ASP.NET pages are precompiled to byte-code and Just In Time (JIT) compiled when first requested. Subsequent requests are directed to the fully compiled code, which is cached until the source changes.

  3. Use services provided by the .NET Framework
    The .NET Framework provides class libraries that can be used by your application. Some of the key classes help you with input/output, access to operating system services, data access, or even debugging. We will go into more detail on some of them in this module.

  4. Graphical Development Environment
    Visual Studio .NET provides a very rich development environment for Web
    developers. You can drag and drop controls and set properties the way you do in Visual Basic 6. And you have full IntelliSense support, not only for your code, but also for HTML and XML.

  5. State management
    To refer to the problems mentioned before, ASP.NET provides solutions for session and application state management. State information can, for example, be kept in memory or stored in a database. It can be shared across Web farms, and state information can be recovered, even if the server fails or the connection breaks down.

  6. Update files while the server is running!
    Components of your application can be updated while the server is online and clients are connected. The Framework will use the new files as soon as they are copied to the application. Removed or old files that are still in use are kept in memory until the clients have finished.

  7. XML-Based Configuration Files
    Configuration settings in ASP.NET are stored in XML files that you can easily read and edit. You can also easily copy these to another server, along with the other files that comprise your application.

Sunday, August 10, 2008

DOTNETNUKE HELP

What is a DotNetNuke Module?
In order to understand what a DotNetNuke module is, it is important to first understand what DotNetNuke is.
DotNetNuke is a Framework
DotNetNuke is a program that runs on Microsoft ASP.NET. It is also a framework, meaning, it is a program that is designed to be extended. One of the ways you extend the framework is to create modules. These modules are installed inside a DotNetNuke DNN4 Module Developers Guide

A single DotNetNuke installation will allow the creation of thousands of individual portals (as much as the server hardware can handle). DotNetNuke portals are configured to display pages and the pages are configured to display modules.

Here I will give you a simple example of making a module in dotnetnuke and implementing it i your DOTNETNUKE application.

To make an application you need:

  1. Visual Studio Express (download)
  2. SQL Server Express (download)
  3. DotNetNuke (download)

Open your DotNetNuke website in Visual Studio.
Right-click on the "DesktopModules" folder and select "New Folder"
Name the folder "SuperSimple"
Next, right-click on the "SuperSimple" folder and select "Add New Item..."
In the "Add New Item" box that opens:
  • Click on "Web User Control" under "Visual Studio Installed Templates".
  • Enter "SuperSimple.ascx" in the "Name" box.
  • Make sure the "Place code in a separate file" box is checked.
  • Click the "Add" button.
  • The "SuperSimple.ascx" file will be created in the "SuperSimple" folder under the "DesktopModules" folder.
Clicking the "plus" icon next to the file will display the associated code behind file "SuperSimple.ascx.vb" (or "SuperSimple.ascx.cs").
Double-click on the "SuperSimple.ascx" file and it will open up in the main editing window. Right now the page will be blank.

Click the "Source" button at the bottom of the page to switch to source view.

Enter the following code:


C#:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SuperSimple.ascx.cs" Inherits="DesktopModules_SuperSimple_SuperSimple" %>
Search: 
<asp:TextBox ID="txtSearch" runat="server">asp:TextBox> 
<asp:Button ID="btnSearch" runat="server" Text="Button" OnClick="btnSearch_Click" /><br />
<br /> 
<asp:GridView ID="GridView1" runat="server">
asp:GridView>
Click the "Design" button at the bottom of the page to switch to the design view.

Double-click on SuperSimple.ascx.cs
Replace all the code with the following code:

using DotNetNuke;
using System.Web.UI;
using System.Text;
using System.Collections.Generic;
using System.Reflection;
using DotNetNuke.Security;
using System.Data.SqlClient;
using System.Data;
using DotNetNuke.Data;
 
partial class DesktopModules_SuperSimple_SuperSimple : DotNetNuke.Entities.Modules.PortalModuleBase 
{    
    protected void Page_Load(object sender, System.EventArgs e) {
        if (!Page.IsPostBack) 
        {
            ShowData("");
        }
    }
    
    protected void btnSearch_Click(object sender, System.EventArgs e) {
        ShowData(txtSearch.Text);
    }
    
    private void ShowData(string SearchString) {
        StringBuilder mySqlString = new StringBuilder();
        mySqlString.Append("SELECT FriendlyName, Description ");
        mySqlString.Append("FROM {databaseOwner}{objectQualifier}DesktopModules ");
        mySqlString.Append("WHERE Description like \'%\' + @SearchString + \'%\' ");
        mySqlString.Append("ORDER BY FriendlyName");
        SqlParameter myParam = new SqlParameter("@SearchString", SqlDbType.VarChar, 150);
        myParam.Value = SearchString;
        this.GridView1.DataSource = ((IDataReader)(DataProvider.Instance().ExecuteSQL(mySqlString.ToString(), myParam)));
        this.GridView1.DataBind();
    }
 
}
Select BUILD from the menu bar and select "Build Page".

The page should build without errors.

While logged into your DotNetNuke site as "host" in the web browser, from the menu bar select "Host". Then select "Module Definitions".

Click the black arrow that is pointing down to make the fly-out menu to appear. On that menu select "Create New Module".

In the Edit Module Definitions menu:
  • Enter "SuperSimple" for MODULE NAME
  • Enter "SuperSimple" for FOLDER TITLE
  • Enter "SuperSimple" for FRIENDLY TITLE
  • Enter "SuperSimple" for DESCRIPTION
  • Enter "1.0" for VERSION

Then click UPDATE


Enter "SuperSimple" for NEW DEFINITION

Then click "Add"

Next, Click "Add Control"

In the Edit Module Control menu:

  • Enter "SuperSimple" for TITLE
  • Use the drop-down to select "DesktopModule/SuperSimple/SuperSimple.ascx" for SOURCE
  • Use the drop-down to select "View" for TYPE

Then click UPDATE

In the upper left hand corner of the website, under the PAGE FUNCTIONS menu click ADD.

In the PAGE MANAGEMENT menu under PAGE DETAILS:

  • Enter "SuperSimple" for PAGE NAME
  • Enter "SuperSimple" for PAGE TITLE
  • Enter "SuperSimple" for DESCRIPTION
  • Click the VIEW PAGE box next to ALL USERS

Then click UPDATE

From the MODULE drop-down select "SuperSimple".

Then click ADD.


This is done and finally you will see your module on your site.

This is the most simple way to make a module in dotnetnuke and add it in your site

I have been searching for FREE SHOPPING CART module on internet bu I couldn't find one . So finally I made the module by my own.

If any one require this module then kindly contact me and I will mail the module to him/her.


How to add a page in Dotnetnuke portal

Log into your existing DotNetNuke installation with a superuser (host) account.
Click the Add icon in the Page Functions section of the control bar (The control bar is located at the top of every page when you are logged in as an administrator or

superuser.)
Fill in the Page Details section

* Page Name: The name of this page, this will be shown in the site menu
* Page Title: The title of the page, this will appear in the browsers title and in the meta tags that search engines index
* Description: A description of this page, this will be stored in the meta tags that search engines index
* Keywords: Key words that pertain to this page's content, these will be stored in the meta tags that search engines index
* Parent Page: The page you wish this page to appear under in the site menu
* Page Template: A page template allows you to quickly create pages with some default content already on them
* Permissions: What DotNetNuke roles can view and/or edit this page


Scroll to the bottom of the page
Click the Update link

How to add a module in dotnetnuke

The Modules menu is found at the top of the page.

Click on the drop down box indicator to show the list of available modules. Select The module you want to add on your page and also select that on which part of the page you want your that module to be placed.
And finally click on the Add button or Add link.

Saturday, August 9, 2008

Templates Available for the controls

IN BRIEF THE TEMPLATES AVAILABLE IN THESE CONTROLS ARE:

TEMPLATE

DESCRIPTION

SUPPORTED BY

AlternatingItemTemplate

Represents the collection of elements and controls that are rendered for every alternating row in the data source.

Repeater and DataList

SelectedItemTemplate

Represents the collection of elements and controls that are rendered when an item is selected in the control

DataList

nbsp;

HeaderTemplate

Represents the collection of elements and controls that are accessed one before any other item is accessed in the control

Repeater, DataList. and DataGrid

FooterTemplate

Represents the collection of elements and controls that are accessed one time after all the items are accessed in the control.

Repeater, DataList, and DataGrid

EditItemTemplate

Represents the collection of elements and controls that are rendered when an item in the server control is in edit mode.

DataList and DataGrid

SeparatorTemplate

Represents the collection of elements and controls that are rendered between each item.

Repeater and DataGrid

PagerTemplate

Represents the collection of elements and controls that are rendered when information is paged

DataGrid

ItemTemplate

Represents the collection of elements and controls that are rendered one time for each data source row

Repeater, DataList, and DataGrid

You can create and edit a template for a server control either by using Visual Designer or by editing ASP.NET code. When you use Visual Designer, the corresponding ASP.NET code is generated automatically.

Controls in ASP.NET

Displays the values of a data source in a table where each column represents a field and each row represents a record. The GridView control enables you to select, sort, and edit these items.

This is the most used control in development.
  • A common question is often asked that which control is better and which is to be used?
There are basically 3 most important controls used to display data.
1)Repeater
2)Detail View
3)Datalist
4)Gridview


Repeater
The Repeater control is a data-bound control that uses templates to display data. The Repeater control works by looping through the records in your data source and then repeating the rendering of one of its templates called the ItemTemplate, one that contains the records that the control needs to render.
A Repeater control can be used to build small and Flexible reports with the templates for the items. It supports the following five templates.
  • HeaderTemplate : Can be used to create the Header Rows of the Table data being presented by Repeater control.
  • FooterTemplate : Can be used to create the Footer Rows of the Table data being presented by Repeater control.
  • ItemTemplate : Used for formatting the Items and rows to be displayed.
  • AlternatingItemTemplate : Alternating items formatting.
  • SeparatorTemplate : Styles for separating rows and columns.
Detail View

The DetailsView control is similar to the GridView control with one notable exception—it displays one record at a time. It is a data-bound user interface control that renders a single record at a time from its associated data source, optionally providing paging buttons to navigate between records.
The DetailsView control displays a single record from a data source, where each data row represents a field in the record. It is often used in combination with a GridView control for master/detail scenarios.
The interesting features in detail view are:
  • Automatic paging and sorting with no coding needed
  • Automatic Insert, Update, and Delete capabilities
  • Complete command button functionality (such as the Edit, Update, and Cancel buttons) without any coding
  • Minimal amount of coding involved than in previous versions of the framework
DATALIST

The DataList control like the Repeater control is a template driven, light weight control, and acts as a container of repeated data items. The templates in this control are used to define the data that it will contain. It is flexible in the sense that you can easily customize the display of one or more records that are displayed in the control. You have a property in the DataList control called RepeatDirection that can be used to customize the layout of the control.

The RepeatDirection property can accept one of two values, that is, Vertical or Horizontal. The RepeatDirection is Vertical by default. However, if you change it to Horizontal, rather than displaying the data as rows and columns, the DataList control will display them as a list of records with the columns in the data rendered displayed as rows.

GRIDVIEW

Displays the values of a data source in a table where each column represents a field and each row represents a record. The GridView control enables you to select, sort, and edit these items.


The GridView control is used to display the values of a data source in a table. Each column represents a field, while each row represents a record. The GridView control supports the following features:

  • Binding to data source controls, such as SqlDataSource.

  • Built-in sort capabilities.

  • Built-in update and delete capabilities.

  • Built-in paging capabilities.

  • Built-in row selection capabilities.

  • Programmatic access to the GridView object model to dynamically set properties, handle events, and so on.

  • Multiple key fields.

  • Multiple data fields for the hyperlink columns.

  • Customizable appearance through themes and styles.














Friday, July 11, 2008

How to add FCK editor in ASP.NET Application

Step 1

Firstly download the FCKeditor .Net package from the fck editor website i. from here fckeditor.net/download.
Step 2

Unzip the downloaded file. There you will find the original source code of the control and a compiled version of it. The file is called

FredCK.FCKeditorV2.dll. It can be in either of the two files:

* bin/Release/1.1/ - the version designed for ASP.NET 1.1
* bin/Release/2.0/ - the version designed for ASP.NET 2.0

Consider the compiled DLL file, and create a reference to it in your project. You have two options to do that:

1. Manually copy the FredCK.FCKeditorV2.dll file to the "bin" directory of your web site.
2. Right-click "References" in your Visual Studio.NET project in the "Solution Explorer". Use "Browse" to select the FredCK.FCKeditorV2.dll file from the

directory you have saved it in.

You can include the control in your Visual Studio.NET controls toolbox. Just right-click on it and select "Choose Items". Then, just point to the

FredCK.FCKeditorV2.dll file by using the "Browse" option. Remember to make sure that you have the latest version of the dll. It may be worthwhile to

recompile from the source if you are having issues getting the upload and connector features to work.
___________________________________
Integration

Step 1

Create an ASP.NET page. To create an instance of the editor, you have two options:

1. Drag and drop the control "FCKeditor" from the toolbox to you page.(this method will only work if you included the "FCKeditor" control in the toolbox -

see Step 2 for the description)
2. Manually add lines of code in your ASP.NET source page:

* Include this line in the top of the page:

<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
NOTE- "<" sign has been removed from the post kindly apply it in place of * *form runat="server">:
*fckeditorv2:fckeditor id="FCKeditor1" runat="server">



Step 2

The editor is now ready to be used. Just open the page in your browser to see it at work.

Tuesday, February 12, 2008

Code to Send message on mobile in asp.net

Public Sub Sendtxtmsg(ByVal cellnumber As String, ByVal objMailTo As String, ByVal content As String)


Dim stringWriterTmp As New StringWriter()
Dim htmlWriter As New HtmlTextWriter(stringWriterTmp)
' Dim htmlContent As String

Dim strContents As String = content

' grvBasketDetail.RenderControl(htmlWriter)
' htmlContent = stringWriterTmp.ToString()
Dim email As String = cellnumber & "@" & objMailTo
Dim message As New MailMessage()
message.From = New MailAddress(ConfigurationManager.AppSettings("MAIL_FROM").ToString(), "name of sender")
If (objMailTo <> "") Then
message.To.Add(New MailAddress(email))
End If
message.Subject = ConfigurationManager.AppSettings("TEXT_MESSAGES_SUBJECT").ToString()
message.Priority = MailPriority.High
message.Body = strContents
message.IsBodyHtml = True
Dim emailClient As New SmtpClient(ConfigurationManager.AppSettings("SmtpServer").ToString())
Dim SMTPUserInfo As New System.Net.NetworkCredential(ConfigurationManager.AppSettings("username").ToString(), ConfigurationManager.AppSettings("Password").ToString())
emailClient.UseDefaultCredentials = False
emailClient.Credentials = SMTPUserInfo
emailClient.Send(message)

End Sub

Sunday, February 10, 2008

CheckBox in gridview with autopostback true

Sometimes we need to have checkboxes in the GridView control and we want that as soon as the Checkbox is clicked/checked the postback happens and we get the value from the first row in the GridView control.

This can be easily done by using the following code:
asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand">
Columns>
asp:BoundField DataField="CategoryID"
HeaderText="CategoryID" />
asp:BoundField DataField="CategoryName"
HeaderText="CategoryName" />
asp:TemplateField HeaderText="Select">
ItemTemplate>
asp:CheckBox ID="CheckBox1"
AutoPostBack="true" runat="server"
OnCheckedChanged="CheckBox1_CheckedChanged1" />
/ItemTemplate>
/asp:TemplateField>
/Columns>
/asp:GridView>

And the code behind:
{
CheckBox checkbox = (CheckBox)sender;
GridViewRow row = (GridViewRow) checkbox.NamingContainer;
Response.Write(row.Cells[0].Text);
}

Ohh by the way when you click a different checkbox it will show you the new value but does not clear the old checkbox. You can make a simple method "ClearCheckboxSelection" which clears all the checkboxes.

Hope you find this example useful :)

CheckBox in gridview with autopostback true

Sometimes we need to have checkboxes in the GridView control and we want that as soon as the Checkbox is clicked/checked the postback happens and we get the value from the first row in the GridView control.

This can be easily done by using the following code:

<asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" onrowcommand="GridView1_RowCommand">
<columns>
<asp:boundfield datafield="CategoryID" headertext="CategoryID">
<asp:boundfield datafield="CategoryName" headertext="CategoryName">
<asp:templatefield headertext="Select">
<itemtemplate>
<asp:checkbox id="CheckBox1" autopostback="true" runat="server" oncheckedchanged="CheckBox1_CheckedChanged1">

</asp:checkbox>
</itemtemplate>
</asp:templatefield>
</asp:boundfield>

And the code behind:

protected void CheckBox1_CheckedChanged1(object sender, EventArgs e)
{
CheckBox checkbox = (CheckBox)sender;
GridViewRow row = (GridViewRow) checkbox.NamingContainer;
Response.Write(row.Cells[0].Text);
}

Ohh by the way when you click a different checkbox it will show you the new value but does not clear the old checkbox. You can make a simple method "ClearCheckboxSelection" which clears all the checkboxes.

Hope you find this example useful :)

Sunday, February 3, 2008

Java Script in ASP.Net RadioButtonList


The below sample code shows how to fire an event for a RadioButtonList control of Asp.Net.

The sample contains the java script function and additionally you need to add the following code in the Page_load event of aspx.cs -
RadioButtonList1.Attributes.Add("onclick","RadioCheck(this);");

function RadioCheck(obj)
{
var srcEl = event.srcElement;
// If the Radio's label is cliked the OnClick is fired twice. To avoid this
if(srcEl.tagName == 'LABEL')
return;

var srcObj = document.getElementById(obj.id+"_"+srcEl.parentElement.parentElement.rowIndex);
if(srcObj)
alert("Selected Radio's Value - "+srcObj.value);
}

Tuesday, January 22, 2008

maintaining the tab order on page postback

The code to set focus to the next control after a postback is given below:
C#
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
WebControl wcICausedPostBack = (WebControl)GetControlThatCausedPostBack(sender as Page);
int indx = wcICausedPostBack.TabIndex;
var ctrl = from control in wcICausedPostBack.Parent.Controls.OfType<WebControl>()
where control.TabIndex > indx
select control;
ctrl.DefaultIfEmpty(wcICausedPostBack).First().Focus();
}
}
protected Control GetControlThatCausedPostBack(Page page)
{
Control control = null;
string ctrlname = page.Request.Params.Get("__EVENTTARGET");
if (ctrlname != null && ctrlname != string.Empty)
{
control = page.FindControl(ctrlname);
}
else
{
foreach (string ctl in page.Request.Form)
{
Control c = page.FindControl(ctl);
if (c is System.Web.UI.WebControls.Button || c is System.Web.UI.WebControls.ImageButton)
{
control = c;
break;
}
}
}
return control;
}

VB.NET
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
Dim wcICausedPostBack As WebControl = CType(GetControlThatCausedPostBack(TryCast(sender, Page)), WebControl)
Dim indx As Integer = wcICausedPostBack.TabIndex
Dim ctrl = _
From control In wcICausedPostBack.Parent.Controls.OfType(Of WebControl)() _
Where control.TabIndex > indx _
Select control
ctrl.DefaultIfEmpty(wcICausedPostBack).First().Focus()
End If
End Sub
Protected Function GetControlThatCausedPostBack(ByVal page As Page) As Control
Dim control As Control = Nothing
Dim ctrlname As String = page.Request.Params.Get("__EVENTTARGET")
If ctrlname IsNot Nothing AndAlso ctrlname <> String.Empty Then
control = page.FindControl(ctrlname)
Else
For Each ctl As String In page.Request.Form
Dim c As Control = page.FindControl(ctl)
If TypeOf c Is System.Web.UI.WebControls.Button OrElse TypeOf c Is System.Web.UI.WebControls.ImageButton Then
control = c
Exit For
End If
Next ctl
End If
Return control
End Function

Tuesday, January 1, 2008

Databound checkboxlist aggravation

Discovered today that the databound checkboxlist items' SELECTED property doesn't reflect what's in the VALUE property. The following code on the checkboxlist databound event hanlder cleared things up for me:

Protected Sub cblRoles_DataBound(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles cblRoles.DataBound

Dim loItem As ListItem = Nothing
For Each loItem In cblRoles.Items
loItem.Selected = loItem.Value
Next
End Sub


Now, when the form loads, the items with Value=True now display with the checkbox selected.

Get the return value from a stored procedure

I just burt more hours than I care to admit figuring out this one. I was using an ObjectDataSource to call a stored proc which inserts records into a couple of tables, then returns the identity of the second table. No matter what I did, I could not retrieve the return_value. Instead, I got "Nothing" in the RETURN_VALUE output parameter.

After reading numerous posts out there, I finally figured out that a Strongly Typed Dataset will populate the RETURN_VALUE with the first column of the first row of the resulting result set. Since my stored proc wan't returning a result set, I was getting nothing. By simply ending the proc with the following, I got my RETURN_VALUE:

-- Do inserts and stuff...

SELECT Scope_Identity()
RETURN Scope_Identity()
END