Thursday, June 2, 2011

GridView vs DataList vs Repeater vs Formview vs DetailsView - which one to choose

Re: GridView vs DataList vs Repeater vs Formview vs DetailsView - which one to choose
Feb 06, 2007 03:39 PM

Feature
Repeater
DataList
GridView
Table layout
No
No
Yes
Flow layout
Yes
Yes
No
Column layout
No
Yes
No
Style properties
No
Yes
Yes
Templates
Yes
Yes
Columns/optional
Select/ Edit/Delete
No
Yes
Yes
Sort
No
No
Yes
Paging
No
No
Yes


Validation functions in JavaScript for Date and Password

<script type="text/javascript" language="javascript">function ValidateDate(inval) {

//var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;//var re = /(?:0[1-9]|[12][0-9]|3[01])\/(?:0[1-9]|1[0-2])\/(?:19|20\d{2})/;
var message = "OK!";
var Day, Mn, Yr;
var re = /^(\d{1,2})[-.\/](\d{1,2})[-.\/](\d{4})$/;
if (!inval.match(re))
message = "Enter Date in Valid Format";

re.exec(inval);
Day = RegExp.$1;
Mn = RegExp.$2;
Yr = RegExp.$3;
var DateVal = Mn + "/" + Day + "/" + Yr;
var dt = new Date(DateVal);
if (dt.getDate() != Day) {
message = "Invalid Day!"}
else if (dt.getMonth() != Mn - 1) {
//this is for the purpose JavaScript starts the month from 0message = "Invalid Month!"}
else if (dt.getFullYear() != Yr) {
message = "Invalid Year!"}
alert(message);

}
function ValidatePassword(inval) {
var message = "";
//alert(inval);var re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{6,}$/;
//alert(re.test(inval));re = /(?=.*\d)/;
message += (re.test(inval) == false) ? "Please enter at least one numeric\n" : "";
re = /(?=.*[a-z])/;
message += (re.test(inval) == false) ? "Please enter at least one small char\n" : "";
re = /(?=.*[A-Z])/;
message += (re.test(inval) == false) ? "Please enter at least one cap char\n" : "";
re = /\w{6,}/;
message += (re.test(inval) == false) ? "Length should be more than 6 chars\n" : "";
if (message != "")
alert(message);
}
</script>



===================================================

<script type="text/javascript" language="javascript">
        function ValidateDate(inval) {
       
            //var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
            //var re = /(?:0[1-9]|[12][0-9]|3[01])\/(?:0[1-9]|1[0-2])\/(?:19|20\d{2})/;
       
            var message = "OK!";
            var Day, Mn, Yr;
            var re = /^(\d{1,2})[-.\/](\d{1,2})[-.\/](\d{4})$/;
            if (!inval.match(re))
                message = "Enter Date in Valid Format";
           
            re.exec(inval);
            Day = RegExp.$1;
            Mn = RegExp.$2;
            Yr = RegExp.$3;
            var DateVal = Mn + "/" + Day + "/" + Yr;
            var dt = new Date(DateVal);
            if (dt.getDate() != Day) {
                message = "Invalid Day!"
            }
            else if (dt.getMonth() != Mn - 1) {
                //this is for the purpose JavaScript starts the month from 0
            message = "Invalid Month!"
            }
            else if (dt.getFullYear() != Yr) {
            message = "Invalid Year!"
            }
            alert(message);
           
        }
        function ValidatePassword(inval) {
            var message = "";
            //alert(inval);
            var re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{6,}$/;
            //alert(re.test(inval));
            re = /(?=.*\d)/;
            message += (re.test(inval) == false) ? "Please enter at least one numeric\n" : "";
            re = /(?=.*[a-z])/;
            message += (re.test(inval) == false) ? "Please enter at least one small char\n" : "";
            re = /(?=.*[A-Z])/;
            message += (re.test(inval) == false) ? "Please enter at least one cap char\n" : "";
            re = /\w{6,}/;
            message += (re.test(inval) == false) ? "Length should be more than 6 chars\n" : "";
            if (message != "")
                alert(message);
        }
    </script>

Javascript Date Validation function

<script language="javascript" >///^\d{5}$/.test('84601')



function IsValidDate(d) {var Day, Mn, Yr;var re = /^(\d{4})[-\/.](\d{1,2})[-\/.](\d{1,2})$/;
// var re = "^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$";
re.exec(d);
Yr = RegExp.$1;
Mn = RegExp.$2;
Day = RegExp.$3;




}

if (!d.match(re)) return false;var DateVal = Mn + "/" + Day + "/" + Yr;var dt = new Date(DateVal);if (dt.getDate() != Day) {return (false);else if (dt.getMonth() != Mn - 1) {//this is for the purpose JavaScript starts the month from 0
}


}

}
return (false);else if (dt.getFullYear() != Yr) {return (false);return (true);</script>




========================================
========================================


USAGE




<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!
<
<
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></title><script language="javascript" >///^\d{5}$/.test('84601')


function IsValidDate(d) {var Day, Mn, Yr;var re = /^(\d{4})[-\/.](\d{1,2})[-\/.](\d{1,2})$/;// var re = "^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$";
re.exec(d);
Yr = RegExp.$1;
Mn = RegExp.$2;
Day = RegExp.$3;




}
if (!d.match(re)) return false;var DateVal = Mn + "/" + Day + "/" + Yr;var dt = new Date(DateVal);if (dt.getDate() != Day) {return (false);else if (dt.getMonth() != Mn - 1) {//this is for the purpose JavaScript starts the month from 0
}


}

}

</
<return (false);else if (dt.getFullYear() != Yr) {return (false);return (true);</script>head>body><form id="form1" runat="server"><div><input value="1999-9-9" id="datavalue" onblur="alert( IsValidDate(document.getElementById('datavalue').value) );"/></div>
</
</</form>body>html>

Monday, May 30, 2011

How to open a pop up window in asp.net ?

A very good discussion at :

http://forums.asp.net/t/883647.aspx


Without Postback :
Button1.Attributes.Add("onclick", "window.open('www.microsoft.com'); return false;");

look at the following :

The onClick attribute is Javascript anyway, so it is wrong to also include the javascript: pseudo-protocol.

That is, the following is wrong:
    Button1.Attributes.Add("onclick", "javascript:window.open('www.microsoft.com'); return false;");

And the following is correct:
    Button1.Attributes.Add("onclick", "window.open('www.microsoft.com'); return false;");

We use the javascript: pseudo-protocol only when altering an href attribute, as by default that is an http:// protocol.

That is, the following is wrong:
    <a href="window.open('www.microsoft.com');">Visit Microsoft</a>

And the following is correct:
    <a href="javascript:window.open('www.microsoft.com');">Visit Microsoft</a>



However if you want deliberate postback , you can use something like :


<%@ Page Language="C#" %>
<%@ Import namespace="System.Text" %>
<script runat="server">
    void Button1_Click(object sender, EventArgs e)
    {
        // Do some other processing...
        StringBuilder sb = new StringBuilder();
        sb.Append("<script>");
        sb.Append("window.open('http://msdn.microsoft.com', '', '');");
        sb.Append("</scri");
        sb.Append("pt>");
        Page.RegisterStartupScript("test", sb.ToString());
    }
</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Go!"></asp:Button>
    </form>
</body>
</html>

How to swap to values in a table ? e.g. 'M' with 'F'



/* APPROACH 1 */
update test set gender = (case when gender = 'M' then 'F' when gender = 'M' then 'F' end )/* APPROACH 2 */
declare @oldvalue varchar(10) = 'M'declare @newvalue varchar(10) = 'F'update test set gender = (case when gender = @oldvalue then @newvalue when gender = @newvalue then @oldvalue end )

Thursday, May 26, 2011

Something important about structs




Structs cannot contain explicit parameterless constructors
Structs can be only public or internal.
Struct members can be public, private or internal.
Struct can nest a class.
If you create a parametersised constructor, you MUST initialise all members in it.

Difference Between Passing a Struct and Passing a Class Reference

http://msdn.microsoft.com/en-US/library/8b0bdca4(v=VS.80).aspx

 

How to: Know the Difference Between Passing a Struct and Passing a Class Reference to a Method (C# Programming Guide)

Comparing features of LangGraph vs CrewAI

LangGraph Orchestration vs CrewAI Orchestration The following table compares LangGraph and CrewAI orchestration across their menta...