Thursday, December 18, 2008

Integration of Aspnet membership DB with your own DataBase

Open Command Promt and change the directory to your .net 2 framework directory e.g. C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727. If you use VS 2008, still you have to go to .net 2 directory not 3.5. Then run the following command -

aspnet_regsql -A mr -C "Data Source=localhost;Initial Catalog=targetDB;Integrated Security=true"

Here the assumption is that the target application database will be targetDB.

After executing this command you will find application database will contain 6 additional tables -

aspnet_Applications,
aspnet_Membership,
aspnet_Roles,
aspnet_SchemaVersions,
aspnet_Users and
aspnet_UsersInRoles

These tables will serve aspnet built-in user & role management. Then in config file add the following connection string -

add name="SqlServices" connectionstring="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=targetDB;

If you don't name the connection string as "SqlServices", you have to configure the membership in config file by yourself.

Wednesday, December 3, 2008

XML data type manipulation in sql server

A very useful link regarding this http://www.15seconds.com/issue/050803.htm.

If your database contains XML data but the field type is text or varchar, then you need to convert or cast the data to XML then manipulate query ,value & exist method described in the above link.

For cast & convert, see http://msdn.microsoft.com/en-us/library/ms187928.aspx

Saturday, October 25, 2008

asp.net validation along with classical javascript validation

Sometimes we need to some conditional validations(e.g. depending on multiple fields) or some complex validations which cannot be performed by asp.net validation. For this reason, we need asp.net validation along with javascript validation.

To perform this, we set the OnClientClick property with a value like this - "return isValidForm()". Note, there return keyword must preceed the function call. Otherwise it will not prevent postback whether validation function isValidForm() return true or false.

then the body of the validation function like this -

function isValidForm()
{
/*
calling javascript validation function with return statement
*/
return Page_ClientValidate();
}

Thursday, September 25, 2008

Some good practices of creating custom .net user control

1. No data binding or logic should be contained in the code.

2. There should be some property to data bind or access the control.

3. JavaScript should be place inside in a .js file because it makes it very easy to make global JavaScript changes to the application.

4. As a web page may contain several instance of the custom control, the JavaScript should not be included for each instance. So for including the JavaScript just for once per page the following code can written in the Page_Load(object sender, EventArgs e) method:

if(!this.Page.ClientScript.IsClientScriptBlockRegistered(keyClientBlock))
{
this.Page.ClientScript.
RegisterClientScriptBlock(this.Page.GetType(),
"keyClientBlock",jScript);
}
Here jScript string contains the JavaScript code.

5. If you need to execute some this javascript to initialize some tool then use RegisterStartupScript() method. The parameter list of this method is same as RegisterClientScriptBlock(). The difference between RegisterStartupScript() & RegisterClientScriptBlock() is that the first one puts the script at the bottom of the ASP.NET page and the latter puts that at the top of the page.

Tuesday, September 23, 2008

Ajax Update panel in DotNetNuke 4.0 or upper

The DotNetNuke Framework cannot assume that the web server it is running on has ASP.NET AJAX installed. In order to handle this a new class was created in DotNetNuke.Framework.AJAX which provides methods that developers can use to leverage AJAX in their solutions. For detail about this the following page can be visited -

Creating A DotNetNuke Module using ASP.NET AJAX

But without following the instructions in this page, you can add ajax support in your dotnetnuke module easily. Follow the instruction step by step:

1. instead of ajax update panel add an asp:panel in the module.

2. override the - void OnInit(EventArgs e) method of module i.e. asp.net custom control.

3. In the override OnInit() method register DotNetNuke Ajax Script Manager by calling the method DotNetNuke.Framework.AJAX.RegisterScriptManager().

4 . Then add your asp:panel for ajax support by calling method DotNetNuke.Framework.AJAX.WrapUpdatePanelControl(#asppanelID#, true);

5. You can also allow postback of this module for a specific control in the asp:panel by calling DotNetNuke.Framework.AJAX.RegisterPostBackControl(#aspPostBackEnableControl#).

Sample code block:

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
try
{
if (DotNetNuke.Framework.AJAX.IsInstalled())
{
DotNetNuke.Framework.AJAX.RegisterScriptManager();
DotNetNuke.Framework.AJAX.
WrapUpdatePanelControl(this.pnlUpdate, true);
DotNetNuke.Framework.AJAX.
RegisterPostBackControl(this.btnSubmit);
}
}
catch (Exception exp)
{
//Step if ajax is not supported.
}
}