Protected: From iPhone

February 13th, 2009
Enter your password to view comments

This post is password protected. To view it please enter your password below:


personal

Supression operator

November 20th, 2008

Putting @ infront of an expression will display any errors generated:

$albert = @$albus;

PHP

Ternary operators

November 20th, 2008

Ternary Operators

$todo = (empty($_POST[’todo’])) ? ‘default’ : $_POST[’todo’];

The above is identical to this if/else statement

if (empty($_POST[’todo’])) {
$action = ‘default’;
} else {
$action = $_POST[’todo’];
}

PHP

Nullable Types

November 18th, 2008

When using the System.Nullable syntax you can substitute it for T?

For example,

System.Nullable<int> intNullable; is the same as
int? intNullable;

If you have declared a non-nullable variable and are assigning it a value that could be null you can use the ?? syntax to give it a default value. For example:

int? intNullable = null;
int intNotNullable = intNullable ?? 99;

Would give the intNotNullable variable a value of 99 in the event of intNullable being null.

.net, c# , ,

Add a confirm Popup in asp .net

November 18th, 2008

To add a confirm popup when a button is clicked in asp .net do the following:

In the buttons OnClientClick add the following javascript:

if(confirm(’Are you sure?’))
{
return true;
}else{
return false;
}

The confirm method returns a boolean.

The popup displays the message, an Ok button and a canel button.

If Ok is clicked return true allows the button to cause a post back.
Clicking cancel returns false cancel the submit action of the button.

ASP .Net, Javascript ,

Modal Popup in IE and Firefox 3

November 18th, 2008

To have a web page popup in a modal page IE has a javascript function

window.showModalDialog(’page url’, ‘page title’, ‘options’);

The syntax for the options is slightly different from window.open

To specify height and width we would do:

‘dialogHeight:300px; dialogWidth:300px’

To make sure the code works cross browser we can check for the showModalDialog function and if it is not available we can you use window.open.

eg.

if (window.showModalDialog)
{
window.showModalDialog(’page.html’,'MyPage’,'dialogWidth:300px;dialogHeight:3000px’);
}else{
window.open(’page.html’,'MyPage’,'width=300, height=300′);
}

Javascript , ,

Using external Javascript with asp .net

November 13th, 2008

If your wanting to add an external javascript file/library to use in your aspx pages then you would usually just add a script tag at the top of the page. This works in most cases but not when you are using master pages, a master page wont recognise your script.

To solve this problem do the following in your master page:

<script type='text/javascript'
src='<%# ResolveUrl ("~/Javascript/jquery-1.2.6.min.js") %>'></script>

Use a data bind expression to reference you javascript in the head block of the master page.

Then in the master page code behind Databind the page header on the page load:

 Page.Header.DataBind ();

ASP .Net , , ,