July 2008 - Posts

A CSS Filter is a coding technique used to hide or show CSS markup depending on the browser's brand and/or version number. Browsers have different interpretations of CSS behavior and different levels of support for the W3C standards. Web developers will implement CSS Filters when attempting to achieve consistent layout appearance in browsers that do not have a consistent CSS behavior.

Below are some CSS Filter Example you can use to give a nice look and feel to your webpages:

 Alpha Channel:
<span style="width: 357; height: 50; font-size: 36pt; font-family: Arial Black; color: red; Filter: Alpha(Opacity=100, FinishOpacity=0, Style=1, StartX=0, StartY=0, FinishX=580, FinishY=0)">"DotNetSlackers"</span>

 Motion Blur:
<span style="width: 357; height: 50; font-size: 36pt; font-family: Arial Black; color: red; Filter: Blur(Add = 1, Direction = 225, Strength = 10)">"DotNetSlackers"</span>

 Chroma:
<span style="width: 580; height: 50; font-size: 36pt; font-family: Arial Black; color: red; Filter: Chroma(Color = #FF0000)">"DotNetSlackers"</span>

 Drop Shadow:
<span style="width: 357; height: 50; font-size: 36pt; font-family: Arial Black; color: blue; Filter: DropShadow(Color=#FF0000, OffX=2, OffY=2, Positive=1)">"DotNetSlackers"</span>

 Flip:
<span style="width: 300; height: 50; font-size: 36pt; font-family: Arial Black; color: red; Filter: FlipV">"DotNetSlackers" </span>

 Glow:
<span style="width: 357; height: 50; font-size: 18pt; font-family: Arial Black; color: red; Filter: Glow(Color=#00FF00, Strength=20)">"DotNetSlackers"</span>

 Grayscale:
<span style="width: 300; height: 50; font-size: 18pt; font-family: Arial Black; color: red; Filter: Gray">"DotNetSlackers" </span>

 Invert:
<span style="width: 387; height: 50; font-size: 18pt; font-family: Arial Black; color: red; Filter: Invert">"DotNetSlackers"</span>

 Mask:
<span style="width: 357; height: 50; font-size: 18pt; font-family: Arial Black; color: red; Filter: Mask(Color=#00FF00)">"DotNetSlackers"</span>

 Shadow:
<span style="width: 357; height: 50; font-size: 18pt; font-family: Arial Black; color: red; Filter: Shadow(Color=#0000FF, Direction=225)">"DotNetSlackers"</span>

 Wave:
<span style="width: 357; height: 50; font-size: 36pt; font-family: Arial Black; color: red; Filter: Wave(Add=0, Freq=5, LightStrength=20, Phase=20, Strength=20)">"DotNetSlackers"</span>

 X-ray:
<span style="width: 357; height: 50; font-size: 36pt; font-family: Arial Black; color: red; Filter: Xray">"DotNetSlackers" </span>

 

Below is the corresponding effects of above example:

you would find excellent SEO related Tips at Pranav's blog

http://pranavgupta.wordpress.com/

I would prefer to always check out this blog to find latest SEO related tips. You would find lists of websites with High PageRanks, free link submission related information, some free SEO Tools information, SEO Tricks to create a perfect HTML Page, Search Optimization basics, some tricks to increase google page ranks etc., He has posted loots of informative SEO Tips and Tricks at this blog you can check out. Cheers!

Posted by kaushalparik | with no comments
Filed under: ,

I have seen posts today asking for Asynchronous Request to Server which will Query the Database for certain information.
Here, I am giving one example, which will send an Asynchronous Request to server for Checking the availablity of the UserName entered by the user against database.

Below is my WebPage:

        <div>
            <asp:Label ID="Label1" runat="server" Text="UserName:"></asp:Label>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return CheckUserNameAvailablity1()" />
        </div>

Here, I have attached a JavaScript Function CheckUserNameAvailablity1() with OnClientClick Property of the Button Control. Below is that JavaScript Function:

    function CheckUserNameAvailablity1()
    {    
        var name=document.getElementById('<%=TextBox1.ClientID%>').value;
        CheckUserNameAvailablity2(name);
        return false;
    }

In turn, this Function is calling another JavaScript Function; CheckUserNameAvailablity2() by passing the Name entered by the User in the TextBox as an argument. Below is that JavaScript Function:

    function CheckUserNameAvailablity2(Name)
    {                    
        try
        {            
            var Source = new ActiveXObject("Microsoft.XMLDOM");
            var XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            var ElemList;            
            var Request = "DOM.aspx?Name=" + Name;
            XmlHttp.open("POST",Request,false);
            XmlHttp.send();
            Source.async = false;                                            
            if (Source.loadXML(XmlHttp.responseText) == true)
            {            
                ElemList = Source.getElementsByTagName("tblAjaxEx");
                if(ElemList.length > 0)                
                    alert("Entered USerName is already Exists..");                
                else
                    alert("Entered UserName is available..");
            }
        }
        catch(Ex)
        {
            alert(Ex.message);
        }        
    }

In this JavaScript function, I am creating one XMLDOM Object to load the retrieved/resulant XML and one XMLHTTP Object to send Asynchrounous Request to Server using "POST" method. XMLHTTP Object will send the Async. Request using POST method as,

        var Request = "DOM.aspx?Name=" + Name;
            XmlHttp.open("POST",Request,false);
            XmlHttp.send();

Here, DOM.aspx is simply a WebPage in which I am filling a DataSet to check whether the UserName entered is already exists in the DataBase or not.
Below is the Code in DOM.aspx page in Page_Load() event:

public partial class DOM : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            CheckUserNameAvailablity(Convert.ToString(Request.QueryString["Name"]).ToUpper());
        }
    }
    private void CheckUserNameAvailablity(string Name)
    {
        DataSet dsDataSet = new DataSet();
        string strSQL = "Select Name From TestUserTable Where Upper(Name) = '" + Name + "'";
        SqlConnection cn = new SqlConnection(ConfigurationManager.AppSettings["cnn"]);
        cn.Open();
        SqlDataAdapter adAdapter = new SqlDataAdapter(strSQL, cn);
        adAdapter.Fill(dsDataSet, "tblAjaxEx");
        Response.Clear();
        if (dsDataSet != null)
            dsDataSet.WriteXml(Response.OutputStream);
        Response.End();
    }
}

In this function, I am filling One DataSet and write the Output in XML format with dsDataSet.WriteXml(Response.OutputStream).
Now, Comming back to CheckUserNameAvailablity2(Name) JavaScript Function, in which the XML Output is loaded in XMLDOM Object and simple check is done that whether DataSet has return any rows from DB which consist the UserName entered by the user as,

            if (Source.loadXML(XmlHttp.responseText) == true)
            {            
                ElemList = Source.getElementsByTagName("tblAjaxEx");
                if(ElemList.length > 0)                
                    alert("Entered USerName is already Exists..");                
                else
                    alert("Entered UserName is available..");
            }

Hope, It would help.

 

In one of my previous blog post, I Described about Mutually Exclusive CheckBox inside GridView.

In this example, there is a "Select All" checkbox in header to select/deselect all the checkboxes inside GridView. MoreOver, if user select all the checkboxes manually one by one, then header checkbox should automatically be selected and vice versa.

Here is the Scenario; There is one TemplateColumn in GridView which is used to Select Row within GridView. So, There will be CheckBox inside ItemTemplate of that TemplateColumn. User would be able to select more than one CheckBox in that Column. And to Select All the CheckBoxes of that colum, There will be a "Select All" CheckBox in HeaderTemplate of that GridView. When user check "Select All" CheckBox in Header, all the checkboxes should be selected and vice versa.



Below is the GridView in my ASPX Page:

        <div>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound" CellPadding="4" ForeColor="#333333" GridLines="None">
                <Columns>
                    <asp:TemplateField HeaderText="Select">
                        <ItemTemplate>
                            <asp:CheckBox ID="chkSelect" runat="server" />
                        </ItemTemplate>
                        <HeaderTemplate>
                            <asp:CheckBox ID="chkSelectAll" runat="server" Text="Select All" onclick="SelectAll(this);" />
                        </HeaderTemplate>
                    </asp:TemplateField>                    
                    <asp:BoundField DataField="Name" HeaderText="Name" />
                </Columns>
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#999999" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            </asp:GridView>
        </div>


As I said, if user select all the checkboxes manually one by one, then header checkbox should automatically be selected and vice versa; for that we have to handle GridView_RowDataBound event handler to attach the JavaScript on "OnClick" event of all CheckBoxes inside GridView.
Below is the Code Behind; where we are attaching the JavaScript on "OnClick" of CheckBox:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {                
                string strScript = "SelectDeSelectHeader(" + ((CheckBox)e.Row.Cells[0].FindControl("chkSelect")).ClientID + ");";
                ((CheckBox)e.Row.Cells[0].FindControl("chkSelect")).Attributes.Add("onclick", strScript);                
            }            
        }
        catch (Exception Ex)
        {
            //report error
        }        
    }

Finally, Below is the JavaScript (to Select/DeSelect all the CheckBoxes inside GridView) which is attached to CheckBox in HeaderTemplate:

    function SelectAll(CheckBox)
    {
        TotalChkBx = parseInt('<%= this.GridView1.Rows.Count %>');    
        var TargetBaseControl = document.getElementById('<%= this.GridView1.ClientID %>');
        var TargetChildControl = "chkSelect";   
        var Inputs = TargetBaseControl.getElementsByTagName("input");
        for(var iCount = 0; iCount < Inputs.length; ++iCount)
        {                
            if(Inputs[iCount].type == 'checkbox' && Inputs[iCount].id.indexOf(TargetChildControl,0) >= 0)
                Inputs[iCount].checked = CheckBox.checked;   
        }
    }

and another JavaScript function that will select the Header "Select All" CheckBox if user select all the checkboxes manually and vice versa:

    function SelectDeSelectHeader(CheckBox)
    {        
        TotalChkBx = parseInt('<%= this.GridView1.Rows.Count %>');    
        var TargetBaseControl = document.getElementById('<%= this.GridView1.ClientID %>');
        var TargetChildControl = "chkSelect";   
        var TargetHeaderControl = "chkSelectAll";   
        var Inputs = TargetBaseControl.getElementsByTagName("input");
        var flag = false;
        var HeaderCheckBox;
        for(var iCount = 0; iCount < Inputs.length ; ++iCount)
        {    
            if(Inputs[iCount].type == 'checkbox' && Inputs[iCount].id.indexOf(TargetHeaderControl,0) >= 0)            
                HeaderCheckBox = Inputs[iCount];            
            if(Inputs[iCount] != CheckBox && Inputs[iCount].type == 'checkbox' && Inputs[iCount].id.indexOf(TargetChildControl,0) >= 0 && Inputs[iCount].id.indexOf(TargetHeaderControl,0) == -1)
            {            
                if(CheckBox.checked)
                {                    
                    if(!Inputs[iCount].checked)                    
                    {                    
                        flag = false;
                        HeaderCheckBox.checked = false;                       
                        return;
                    }
                    else
                        flag = true;                    
                }
                else if(!CheckBox.checked)                
                    HeaderCheckBox.checked = false;                                                       
            }            
        }                      
        if(flag)        
            HeaderCheckBox.checked = CheckBox.checked        
    }

Hope it will help them who want to develop some what similar or exact this functionality.

 

I was having a development requirement in which i have to implement CheckBoxes inside GridView.
Scenario is like, There is one TemplateColumn in GridView which is used to Select any Row within GridView. So, There will be CheckBox inside ItemTemplate of that TemplateColumn.

User would be able to select only one CheckBox (Mutually Exclusive) in that Column. If user select any other CheckBox in that Column, then Previously Selected CheckBox should be unchecked.
Here, I cant use RadioButton, as User should also be able to deselect the selected CheckBox, which is not possible with RadioButton.

To accomplish this scenario, we just need to attach a JavaScript function which traverse through all the "Input" elements of the Web Page form.
You will get all the elements by; var elm = document.getElementsByTagName('input');.
While Traversing the elements in a Loop; check for the ID of the current Traversing element with the ID of the selected CheckBox. We will pass the ID of the selected CheckBox in argument of the function.



Below is the GridView in my ASPX Page:

        <div>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound" CellPadding="4" ForeColor="#333333" GridLines="None">
                <Columns>
                    <asp:TemplateField HeaderText="Select">
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox1" runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>                    
                    <asp:BoundField DataField="Name" HeaderText="Name" />
                </Columns>
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#999999" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            </asp:GridView>
        </div>

There is a CheckBox TemplateColumn and we have to handle GridView_RowDataBound event handler to attach the JavaScript on "OnClick" event of the CheckBox.
Below is the Code Behind; where we are attaching the JavaScript on "OnClick" of CheckBox:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string strScript = "uncheckOthers(" + ((CheckBox)e.Row.Cells[0].FindControl("CheckBox1")).ClientID + ");";
                ((CheckBox)e.Row.Cells[0].FindControl("CheckBox1")).Attributes.Add("onclick", strScript);                
            }            
        }
        catch (Exception Ex)
        {
            //report error
        }        
    }

And Finally the JavaScript which consists the main functionality of Mutually Exclusive CheckBox:

    <script type="text/javascript" language="javascript">
    function uncheckOthers(id)
    {        
        var elm = document.getElementsByTagName('input');        
        for(var i = 0; i < elm.length; i++)
        {                            
            if(elm.item(i).id.substring(id.id.lastIndexOf('_')) == id.id.substring(id.id.lastIndexOf('_')))
            {
                if( elm.item(i).type == "checkbox" && elm.item(i)!=id)
                    elm.item(i).checked = false;
            }
        }
    }        
    </script>

This would compel the user to select only one CheckBox inside one perticular Column inside GridView. The code will work with more than one TemplateColumn with CheckBox inside GridView.
Hope it will help them who want to develop the functionality.

 

I was having few hours of work-a-round when I was trying to Set-up/Deploy the DotNetNuke Environment at my local pc.
I restore the DB Backup of DNN, copied the source at my local pc drive and configured the Virtual Directory for the application.
I also made the changes in Web.Config file; that is Connection String related changes.

As we have to specify the Portal Alias in PortalAlias Table in DBB DataBase, I defined it as localhost/dnnapp (you need to make sure that this would be the first PortalAlias entry, like localhost/dnnapp; and Do not add the http:// part.

After all these settings, I hopefully tried to access the application with "http://localhost/dnnapp" URL; but I got one (it seemed to me a common error) error, "Invalid URI: The hostname could not be parsed". I again checked my DataBase Settings (UserID, pwd, PortalAlias etc.) , Web.Config Settings; but didn't get any success; except some variation in error message; that is "Page cannot be displayed". But the most common error I was having is of "Invalid URL:  The hostname could not be parsed" only. Lastly, I attempted to stop IIS and start it again, and it worked finally. I am not sure that this is the solution of this error message but it worked for me.

 

Posted by kaushalparik | 8 comment(s)
Filed under: ,

I am delighted to find out that I have been awarded with 2008 Microsoft® MVP Award.

This is the email I received:


Subject: [MVP] Congratulations! You have received the Microsoft MVP Award

Dear Kaushal Parik,  
 
Congratulations! We are pleased to present you with the 2008 Microsoft® MVP Award! The MVP Award is our way to say thank you for promoting the spirit of community and improving people’s lives and the industry’s success every day. We appreciate your extraordinary efforts in ASP/ASP.NET technical communities during the past year.


I am really very excited and I'd like to thank the personnel who nominated me. (If anybody who nominated me and reading this, then please reveal yourself to me, so I can personally thank you.)

 

Posted by kaushalparik | 2 comment(s)
Filed under:

I came across one good article on Dynamic SQL (SQL Server) by Erland Sommarskog, SQL Server MVP.

The Article describes Intro to Dynamic SQL, SQL Injection, Dynamic Queries and SPs, Good Coding Practice and Tips for Dynamic SQL, and the common cases where not to use Dynamic SQL:


In this article I will discuss the use of dynamic SQL in stored procedures and to a minor extent from client languages. To set the scene, I start with a very quick overview on application architecture for data access. I then proceed to describe the feature dynamic SQL as such, with a quick introduction followed by the gory syntax details. Next, I continue with a discussion on SQL injection, a security issue that you absolutely must have good understanding of when you work with dynamic SQL. This is followed by a section where I discuss why we use stored procedures, and how that is affected by the use of dynamic SQL. I carryon with a section on good practices and tips for writing dynamic SQL. I conclude by reviewing a number of situations where you could use dynamic SQL and whether it is a good or bad idea to do it. Read More...

Posted by kaushalparik | 2 comment(s)
Filed under: