Showing posts with label Web Development. Show all posts
Showing posts with label Web Development. Show all posts

Friday, December 21, 2007

Can TextBox.Text ever be null?

Recently I have been asked this question. Answer is that it cannot be null and will not be null, so you don't have to:
.Text != null

Why? Because .Text property in base class does:
    set 
{
if (value == null)
{
value = "";
}
.....
}

Above is for TextBox from Windows.Forms, as for TextBox from WebControls it's the same. The getter looks like this:
    get 
{
string str = (string) this.ViewState["Text"];
if (str != null)
{
return str;
}
return string.Empty;
}

If you don't believe me just try to assign a null value :-)

Wednesday, November 29, 2006

HeaderImageUrl overwrites HeaderText

If you set up HeaderImageUrl property in HyperLinkColumn, the text from HeaderText will not be shown.
Take this code for example:

<asp:HyperLinkColumn DataTextField="urn:schemas-microsoft-com:office:office#Author"
DataNavigateUrlField="urn:schemas-microsoft-com:office:office#Author"
DataNavigateUrlFormatString="/MySite/Public.aspx?user={0}"
HeaderText="Author" HeaderImageUrl="/_layouts/images/imnhdr.gif">


The "Author" text will not be shown in this column's header. Only the icon will be visible. Well there is a simple way to solve

this:


<asp:HyperLinkColumn DataTextField="urn:schemas-microsoft-com:office:office#Author"
DataNavigateUrlField="urn:schemas-microsoft-com:office:office#Author"
DataNavigateUrlFormatString="/MySite/Public.aspx?user={0}"
HeaderText="<img src='/_layouts/images/imnhdr.gif'/>Author">


hey, it works :-)

Sunday, June 19, 2005

Group validators in ASP.NET on client side – finally!

Finally that time came. Time to face with the lack of group validators problem. I had two choices: loop up a solution for that in the Internet or fix it on my own.
I decided that first I will try to find something on the Internet. Maximum time for that is 20 minutes, after that I’m fixing it on my own.

After about 5 minutes I have found a fix for that.

I found it on ASP.NET forums. It’s a post by jgallant (Joe Gallant I presume)
http://forums.asp.net/296304/ShowPost.aspx Check out Joe's post on how to implement it.

I found that the posted WebUIValidation.js file didn’t worked for me, so I fixed it.
Plus I added a little patch that when a button doesn’t have assigned validator it validates all (before JavaScript error showed up)

You can view and download my version of this file WebUIValidation.js.txt (look out for the txt extension).

Big thanks Joe for posting this and for a detailed explanation.

Blogger does not let you attach files to posts so here is the content of the "WebUIValidation.js" file


var Page_ValidationVer = "125";

var Page_IsValid = true;

var Page_BlockSubmit = false;

function ValidatorUpdateDisplay(val) {

if (typeof(val.display) == "string") {

if (val.display == "None") {

return;

}

if (val.display == "Dynamic") {

val.style.display = val.isvalid ? "none" : "inline";

return;

}

}

val.style.visibility = val.isvalid ? "hidden" : "visible";

}

function ValidatorUpdateIsValid() {

var i;

for (i = 0; i < page_isvalid =" false;" page_isvalid =" true;" ctrl =" document.all[controlID];" isvalid =" true;" enabled =" false;" i =" 0;" inner =" control;" i =" 0;" validators =" new" type ="="" ev =" control.onclick;" ev =" control.onchange;" ev =" ev.toString();" ev =" ev.substring(ev.indexOf(" ev = "" func =" new" type ="="" onclick =" func;" onchange =" func;" control =" document.all[id];" j="0;" inner =" control[j];" status ="="" status ="="" i =" 0;">< page_validators =" eval(Page_Validators);" i =" 0;" isvalid =" true;" i =" 0;" page_blocksubmit =" !Page_IsValid;" result =" !Page_BlockSubmit;" page_blocksubmit =" false;" returnvalue =" result;" enabled =" (enable" vals =" event.srcElement.Validators;" i =" 0;" isvalid =" true;" isvalid =" val.evaluationfunction(val);" i =" 0;" val =" Page_Validators;" evaluationfunction = " + val.evaluationfunction + " isvalid ="="" isvalid =" false;" page_isvalid =" false;" isvalid =" true;" isvalid =" true;" enabled =" (val.enabled" page_validationactive =" true;" datatype ="="" exp =" /^\s*[-\+]?\d+\s*$/;" num =" parseInt(op," datatype ="="" exp =" new" m =" op.match(exp);" m ="="" cleaninput =" m[1]">0 ? m[2] : "0") + "." + m[4];

num = parseFloat(cleanInput);

return (isNaN(num) ? null : num);

}

else if (dataType == "Currency") {

exp = new RegExp("^\\s*([-\\+])?(((\\d+)\\" + val.groupchar + ")*)(\\d+)"

+ ((val.digits > 0) ? "(\\" + val.decimalchar + "(\\d{1," + val.digits + "}))?" : "")

+ "\\s*$");

m = op.match(exp);

if (m == null)

return null;

var intermed = m[2] + m[5] ;

cleanInput = m[1] + intermed.replace(new RegExp("(\\" + val.groupchar + ")", "g"), "") + ((val.digits > 0) ? "." + m[7] : 0);

num = parseFloat(cleanInput);

return (isNaN(num) ? null : num);

}

else if (dataType == "Date") {

var yearFirstExp = new RegExp("^\\s*((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})\\s*$");

m = op.match(yearFirstExp);

var day, month, year;

if (m != null && (m[2].length == 4 || val.dateorder == "ymd")) {

day = m[6];

month = m[5];

year = (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10))

}

else {

if (val.dateorder == "ymd"){

return null;

}

var yearLastExp = new RegExp("^\\s*(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))\\s*$");

m = op.match(yearLastExp);

if (m == null) {

return null;

}

if (val.dateorder == "mdy") {

day = m[3];

month = m[1];

}

else {

day = m[1];

month = m[3];


}

year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10))

}

month -= 1;

var date = new Date(year, month, day);

return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate()) ? date.valueOf() : null;

}

else {

return op.toString();

}

}

function ValidatorCompare(operand1, operand2, operator, val) {

var dataType = val.type;

var op1, op2;

if ((op1 = ValidatorConvert(operand1, dataType, val)) == null)

return false;

if (operator == "DataTypeCheck")

return true;

if ((op2 = ValidatorConvert(operand2, dataType, val)) == null)

return true;

switch (operator) {

case "NotEqual":

return (op1 != op2);

case "GreaterThan":

return (op1 > op2);

case "GreaterThanEqual":

return (op1 >= op2);

case "LessThan":

return (op1 < op1 ="="" value =" ValidatorGetValue(val.controltovalidate);" length ="="" compareto = "" null ="="" compareto =" val.valuetocompare;" compareto =" ValidatorGetValue(val.controltocompare);" value = "" value =" ValidatorGetValue(val.controltovalidate);" length ="="" args =" {" value =" ValidatorGetValue(val.controltovalidate);" length ="="" rx =" new" matches =" rx.exec(value);" value ="="" m =" s.match(/^\s*(\S+(\s+\S+)*)\s*$/);" m ="="" value =" ValidatorGetValue(val.controltovalidate);" length ="="" sums =" 0;" summary =" Page_ValidationSummaries[sums];" display = "none" display = "" displaymode = "BulletList" headersep =" ">
";

first = "";

pre = "";

post = "
";

final = "";

break;

case "BulletList":

default:

headerSep = "";

first = "
    ";

    pre = "
  • ";

    post = "
  • ";

    final = "
";

break;

case "SingleParagraph":

headerSep = " ";

first = "";

pre = "";

post = " ";

final = "
";

break;

}

s = "";

if (typeof(summary.headertext) == "string") {

s += summary.headertext + headerSep;

}

s += first;

for (i=0; i

";

}

for (i=0; i

";

break;

case "BulletList":

default:

s += " - " + Page_Validators.errormessage + "
";

break;

case "SingleParagraph":

s += Page_Validators.errormessage + " ";

break;

}

}

}

span = document.createElement("SPAN");

span.innerHTML = s;

s = span.innerText;

alert(s);

}

}

}

}

function InArray(array, value, attribute)

{

if( attribute != null )

attribute += ".";



for(var i = 0; i <>

{

if( eval('array.' + attribute + 'toString().toLowerCase()') == value.toString().toLowerCase() )

return i;

}

return -1;

}

Monday, March 28, 2005

Spice Up Your UI

Introduction
(...)
Internet Explorer contains many little-known and hidden features that, given the right circumstances, you can use to your advantage when developing Web sites. Because many of these features are specific to Internet Explorer, and are not available on any other browser, you should probably only consider using them when you are developing in an environment like a corporate intranet or some other controlled environment where you can guarantee that everyone who uses the site will be using Internet Explorer. Given that caveat, there is really no reason why you cannot take advantage of these powerful features.

In this installment of “UI Tips” we are looking at transitions and filters. Transitions and filters are UI capabilities that have been present in IE since version 4, but were greatly enhanced with version 5.5 and now include a variety of visual effects, which we’ll review and demonstrate here.
(…)

Very interesting article, check it out here