[sourcecode language="csharp"]
ContentPlaceHolder holder = Page.Master.FindControl("message") as ContentPlaceHolder;
HtmlGenericControl alertControl = new HtmlGenericControl();
alertControl.Attributes["class"] = "alert alert-success";
alertControl.TagName = "div";
holder.Controls.Add(alertControl);
Label message = new Label();
message.Text = "User deleted successfully.";
alertControl.Controls.Add(message);
[/sourcecode]
Friday, March 20, 2015
Friday, March 13, 2015
OpenLayers 3 Map with Marker

[sourcecode language="html"]
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="http://openlayers.org/en/v3.2.1/css/ol.css" type="text/css">
<style>
.map {
height: 400px;
width: 100%;
}
</style>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://openlayers.org/en/v3.2.1/build/ol.js" type="text/javascript"></script>
<title>OpenLayers 3 example</title>
</head>
<body>
<h2>My Map</h2>
<div id="map" class="map"></div>
<script>
var map = new ol.Map({
target: 'map',
renderer: 'canvas',
layers: [
new ol.layer.Tile({source: new ol.source.OSM()})
],
view: new ol.View({
//projection: 'EPSG:900913',
center: ol.proj.transform([80.6350, 7.2964], 'EPSG:4326', 'EPSG:3857'),
zoom: 10
})
});
//Full Screen
var myFullScreenControl = new ol.control.FullScreen();
map.addControl(myFullScreenControl);
map.addOverlay(new ol.Overlay({
position: ol.proj.transform(
[80.6350, 7.2964],
'EPSG:4326',
'EPSG:3857'
),
element: $('<img src="//map.geo.admin.ch/1403704943/img/marker.png">')
}));
map.on('singleclick', function(evt) {
var coord = evt.coordinate;
var transformed_coordinate = ol.proj.transform(coord, "EPSG:900913", "EPSG:4326");
console.log(transformed_coordinate);
});
</script>
</body>
</html>
[/sourcecode]
Saturday, March 7, 2015
ASP.Net Validating CheckBoxList with JavaScript
[sourcecode language="csharp"]
<asp:CheckBoxList ID="groupsList" runat="server" DataSourceID="GroupsDS" DataTextField="Name" DataValueField="Id" CssClass="span6 m-wrap groupsList" RepeatLayout="UnorderedList"></asp:CheckBoxList>
<asp:CustomValidator ID="CustomValidator1" ErrorMessage="Please select at least one group."
ForeColor="Red" ClientValidationFunction="ValidateCheckBoxList" runat="server" />
<asp:SqlDataSource runat="server" ID="GroupsDS" ConnectionString='<%$ ConnectionStrings:flexi_stocky %>' SelectCommand="SELECT * FROM [Groups]"></asp:SqlDataSource>
[/sourcecode]
[sourcecode language="javascript"]
<script type="text/javascript">
function ValidateCheckBoxList(sender, args) {
var checkBoxList = document.getElementById("<%=groupsList.ClientID %>");
var checkboxes = checkBoxList.getElementsByTagName("input");
var isValid = false;
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) {
isValid = true;
break;
}
}
args.IsValid = isValid;
}
</script>
[/sourcecode]
<asp:CheckBoxList ID="groupsList" runat="server" DataSourceID="GroupsDS" DataTextField="Name" DataValueField="Id" CssClass="span6 m-wrap groupsList" RepeatLayout="UnorderedList"></asp:CheckBoxList>
<asp:CustomValidator ID="CustomValidator1" ErrorMessage="Please select at least one group."
ForeColor="Red" ClientValidationFunction="ValidateCheckBoxList" runat="server" />
<asp:SqlDataSource runat="server" ID="GroupsDS" ConnectionString='<%$ ConnectionStrings:flexi_stocky %>' SelectCommand="SELECT * FROM [Groups]"></asp:SqlDataSource>
[/sourcecode]
[sourcecode language="javascript"]
<script type="text/javascript">
function ValidateCheckBoxList(sender, args) {
var checkBoxList = document.getElementById("<%=groupsList.ClientID %>");
var checkboxes = checkBoxList.getElementsByTagName("input");
var isValid = false;
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) {
isValid = true;
break;
}
}
args.IsValid = isValid;
}
</script>
[/sourcecode]
Friday, March 6, 2015
ASP.NET GridView ListBox Column Data Binding
[sourcecode language="c-sharp"]
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" CssClass="table" DataSourceID="GenericNamesDataSource" DataKeyNames="Id">
<Columns>
<asp:TemplateField HeaderText="Group Name" SortExpression="GroupName">
<EditItemTemplate>
<asp:ListBox ID="ListBox2" runat="server" DataSourceID="GroupsDataSource" DataTextField="Name" DataValueField="Id" SelectedValue='<%# Bind("GroupId") %>' SelectionMode="Multiple" CssClass="chzn-select" autocomplete="off" data-placeholder="Select Item(s)"></asp:ListBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("GroupName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="GenericNamesDataSource" runat="server" ConnectionString='<%$ ConnectionStrings:flexi_stocky %>'
SelectCommand="SELECT GN.Id, GN.GroupId, GN.CreatedAt, G.Name AS GroupName FROM GenericNames AS GN INNER JOIN Groups AS G ON GN.GroupId = G.Id">
</asp:SqlDataSource>
<asp:SqlDataSource ID="GroupsDataSource" runat="server" ConnectionString='<%$ ConnectionStrings:flexi_stocky %>' SelectCommand="SELECT DISTINCT [Id], [Name] FROM [Groups]"></asp:SqlDataSource>
[/sourcecode]
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" CssClass="table" DataSourceID="GenericNamesDataSource" DataKeyNames="Id">
<Columns>
<asp:TemplateField HeaderText="Group Name" SortExpression="GroupName">
<EditItemTemplate>
<asp:ListBox ID="ListBox2" runat="server" DataSourceID="GroupsDataSource" DataTextField="Name" DataValueField="Id" SelectedValue='<%# Bind("GroupId") %>' SelectionMode="Multiple" CssClass="chzn-select" autocomplete="off" data-placeholder="Select Item(s)"></asp:ListBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("GroupName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="GenericNamesDataSource" runat="server" ConnectionString='<%$ ConnectionStrings:flexi_stocky %>'
SelectCommand="SELECT GN.Id, GN.GroupId, GN.CreatedAt, G.Name AS GroupName FROM GenericNames AS GN INNER JOIN Groups AS G ON GN.GroupId = G.Id">
</asp:SqlDataSource>
<asp:SqlDataSource ID="GroupsDataSource" runat="server" ConnectionString='<%$ ConnectionStrings:flexi_stocky %>' SelectCommand="SELECT DISTINCT [Id], [Name] FROM [Groups]"></asp:SqlDataSource>
[/sourcecode]
Sunday, November 30, 2014
JavaScript How to Interact with Parent window from child window
parent.html
[sourcecode language="html"]
<html>
<head>
<script >
// assigning new property with function so child window can point it
document.functionToBeCalledFromChildWindow = function (param){
alert(param);
}
</script>
</head>
<body>
<div id="response"></div>
<button onClick="window.open('child.html', '_blank', 'width=500,height=500')">Open window</button>
</body>
</html>
[/sourcecode]
child.html
[sourcecode language="html"]
<html>
<head>
</head>
<body>
<script >
window.onload = after;
function after(evt)
{
}
//Here we call function "functionToBeCalledFromChildWindow" in parent window.
//window.opener.document.functionToBeCalledFromChildWindow('Mom, U there?');
//Here we access DOM in parent.
window.opener.document.getElementById("response").innerHTML = "Success";
window.close();
opener.window.focus()
</script>
Hi I am the only child here.
</body>
</html>
[/sourcecode]
Monday, November 17, 2014
Download Australian Postcode Data
Buy Now $30.00
Postcodes 2,952
Suburbs 14,665
States
New South Wales
South Australia
Western Australia
Queensland
Tasmania
Victoria
Self-governing territories
Australian Capital Territory
Northern Territory
Sample Data set
Features
- Available in multiple formats - .csv .sql .doc .json .xml .yml .ods .odt .pdf
- Easy integration for existing or new web sites, mobiles apps...etc.
- Well-ordered, clean data set
- GIS related PHP scripts and functions free for developers
- Satisfaction

Contact us for any queries.
* Please note that there may be slight accuracy related problems in the data set as Australian postcodes are changing constantly.
Friday, July 25, 2014
iPhone Push Notifications PHP Server
[sourcecode language="php"]
<?php
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', YOUR_.PEM_FILE);
stream_context_set_option($ctx, 'ssl', 'passphrase', YOUR_PASSPHRASE);
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp) {
exit("Failed to connect: $err $errstr<BR><BR>");
}
echo 'Connected to APN<BR>';
// Create the payload body
$body['aps'] = array(
'badge' => +1,
'alert' => 'Testing push notifications',
'sound' => 'new_wall_paper.wav',
'action-loc-key' => 'OK'
);
$payload = json_encode($body);
for ($i = 0; $i < count($tokens); $i++) {
$msg = chr(0) . pack('n', 32) . pack('H*', $tokens [$i]) . pack('n', strlen($payload)) . $payload;
fwrite($fp, $msg, strlen($msg));
}
echo "Completed sending messages";
fclose($fp);
[/sourcecode]
Monday, June 30, 2014
Passing Multiple Parameters to Form Validation Custom Callbacks in Codeigniter
[caption id="attachment_979" align="aligncenter" width="225"]
Codeigniter Custom Callbacks[/caption]
CI natively only allows for single parameter in custom callbacks. For an instance see the following code.
[sourcecode language="php"]
$this->form_validation->set_rules
('hstate', 'State', 'required|callback_suburb_check[' . $suburb . ']');
[/sourcecode]
If you need to pass multiple parameters, you have several options. Obviously you can change CI behaviour by subclassing the core library. But in this tutorial we follow the less pain approach. That 's to access required parameters via POST variables within your custom callback function. They are still available in this scope.
There is another way using your PHP string handling knowledge. Just formatting all the parameters as single string and passing to the callback function.
[sourcecode language="php"]
$parameters = 'first_arg' . '||' . 'second_arg' . '||' . 'third_arg';
$this->form_validation->set_rules
('some_field', 'Some Field Name', 'callback__my_callback_function['.$parameters.']');
[/sourcecode]
Then in your callback,
[sourcecode language="php"]
function _my_callback_function($field_value, $second_parameter){
list($first_param, $second_param, $third_param) = split('||', $second_parameter);
...
}
[/sourcecode]
CI natively only allows for single parameter in custom callbacks. For an instance see the following code.
[sourcecode language="php"]
$this->form_validation->set_rules
('hstate', 'State', 'required|callback_suburb_check[' . $suburb . ']');
[/sourcecode]
If you need to pass multiple parameters, you have several options. Obviously you can change CI behaviour by subclassing the core library. But in this tutorial we follow the less pain approach. That 's to access required parameters via POST variables within your custom callback function. They are still available in this scope.
There is another way using your PHP string handling knowledge. Just formatting all the parameters as single string and passing to the callback function.
[sourcecode language="php"]
$parameters = 'first_arg' . '||' . 'second_arg' . '||' . 'third_arg';
$this->form_validation->set_rules
('some_field', 'Some Field Name', 'callback__my_callback_function['.$parameters.']');
[/sourcecode]
Then in your callback,
[sourcecode language="php"]
function _my_callback_function($field_value, $second_parameter){
list($first_param, $second_param, $third_param) = split('||', $second_parameter);
...
}
[/sourcecode]
Thursday, June 26, 2014
How to check HTML5 Web Storage Support in JavaScript?
[caption id="attachment_879" align="alignnone" width="372"]
HTML5 Data Storage[/caption]
[sourcecode language="javascript"]
function supports_html5_storage() {
try {
return 'sessionStorage' in window && window['sessionStorage'] !== null;
} catch (e) {
return false;
}
}
alert(supports_html5_storage());
[/sourcecode]
[sourcecode language="javascript"]
function supports_html5_storage() {
try {
return 'sessionStorage' in window && window['sessionStorage'] !== null;
} catch (e) {
return false;
}
}
alert(supports_html5_storage());
[/sourcecode]
Saturday, May 3, 2014
How to remove index.php from CodeIgniter URL in Ubuntu
[caption id="attachment_979" align="aligncenter" width="225"]
CodeIgniter[/caption]
In
to:
Create or modify .htaccess in project root with following content.
Also allow overriding htaccess in your apache
and edit the file & change to
and
Restart Apache
or:
or:
In
application/config/config.php change:$config['index_page']='index.php';to:
$config['index_page']='';Create or modify .htaccess in project root with following content.
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>Also allow overriding htaccess in your apache
/etc/apache2/sites-available/defaultand edit the file & change to
AllowOverrideAlland
Restart Apache
sudo /etc/init.d/apache2 reloador:
sudo service apache2 reloador:
sudo /etc/init.d/httpd reload
Thursday, May 1, 2014
How to Install PhoneGap in Ubuntu
[caption id="attachment_975" align="aligncenter" width="599"]
PhoneGap[/caption]
1. First, check you’ve got Java and Ant installed – you’ll need those later:
2. Install npm
3. Get the latest nodejs (by installing ‘n’ and running that):
4. Now install phonegap itself
5. Download the Android sdk from http://developer.android.com/sdk/index.html, put it somewhere sensible and unpack it:
6. Update PATH in ~/.bashrc to include the phonegap tools:
and then ‘source ~/.bashrc’ to make sure you’ve got the new path setup.
7. Create a phonegap app (I use a “projects” subdirectoy):
8. Before you run the app, you’ll need to set up an emulator – run the android tool:
9. You may need to select a target (e.g. “Android 4.2.2 (API 17)”), and click the “Install 8 packages..” button (may need several clicks to accept all the licences)
Now setup and start an emulator – in the ‘android’ util, go to Tools -> Manage AVDs, go to the “Device Definitions”, select a device, and use the “Create AVD” button to create a new AVD. Then use the “Start..” button to start the AVD (it may take a surprisingly long time to start fully).
Run the app:
You should see the app compile and install on the emulator.
You can do the compile and install steps separately:
10. Add plugins
Optional Step
Original tutorial found at
http://julianhigman.com/blog/2013/10/17/notes-on-setting-up-phonegap-on-ubuntu-for-android-app-development/
1. First, check you’ve got Java and Ant installed – you’ll need those later:
sudo apt-get install default-jre
sudo apt-get install default-jdk
sudo apt-get install ant
2. Install npm
sudo apt-get install npm
3. Get the latest nodejs (by installing ‘n’ and running that):
sudo npm update npm -g
sudo npm install n -g
sudo n stable
4. Now install phonegap itself
sudo npm install -g phonegap
5. Download the Android sdk from http://developer.android.com/sdk/index.html, put it somewhere sensible and unpack it:
sudo mv ~/Downloads/adt-bundle-linux-x86-20130917.zip /opt/
cd /opt
sudo unzip adt-bundle-linux-x86-20130917.zip
sudo chmod -R 777 /opt/adt-bundle-linux-x86-20130917
6. Update PATH in ~/.bashrc to include the phonegap tools:
# Add android sdk
PATH=$PATH:/opt/adt-bundle-linux-x86-20130917/sdk/platform-tools:/opt/adt-bundle-linux-x86-20130917/sdk/tools
and then ‘source ~/.bashrc’ to make sure you’ve got the new path setup.
7. Create a phonegap app (I use a “projects” subdirectoy):
cd ~/projects
phonegap create my-app
cd my-app
8. Before you run the app, you’ll need to set up an emulator – run the android tool:
android
9. You may need to select a target (e.g. “Android 4.2.2 (API 17)”), and click the “Install 8 packages..” button (may need several clicks to accept all the licences)
Now setup and start an emulator – in the ‘android’ util, go to Tools -> Manage AVDs, go to the “Device Definitions”, select a device, and use the “Create AVD” button to create a new AVD. Then use the “Start..” button to start the AVD (it may take a surprisingly long time to start fully).
Run the app:
phonegap local run android
You should see the app compile and install on the emulator.
You can do the compile and install steps separately:
phonegap local build android
phonegap install android
10. Add plugins
Optional Step
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-media.git
Original tutorial found at
http://julianhigman.com/blog/2013/10/17/notes-on-setting-up-phonegap-on-ubuntu-for-android-app-development/
Subscribe to:
Posts (Atom)
How to enable CORS in Laravel 5
https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...
-
Today we are going to build another restful web service in eclipse using gson library. When client makes a request, the application queries ...
-
To import Excel data, first you need to have a Excel reader. It should be accurate enough to interpret Excel data as expected. There 's ...

