Monday, August 18, 2008
SCRIPTSTER. East Java Baker: GridView Delete, with Confirmation
GridViewRowEventArgs e
{
if e.Row.RowType DataControlRowType.DataRow
{
LinkButton l LinkButton e.Row.FindControl LinkButton1 ;
l.Attributes.Add onclick , javascript return +
CONFIRM Are you sure you want to delete this record +
DataBinder.Eval e.Row.DataItem, CategoryID + ;
}
}"
Wednesday, July 30, 2008
Logging HTTP Referals with ASP.NET
public void Application_OnPostRequestHandlerExecute(Object sender, EventArgs e)
{
ReferralLogger rlLogger;
if (String.Empty != Request.QueryString.ToString())
// We have query parameters so we need to log those as well
// as the current page name
rlLogger = new ReferralLogger(Request.Path.ToString()+"?"
Request.QueryString.ToString(),
Request.UrlReferrer);
else
// No query string, so simply log the request and the referring URL
rlLogger = new ReferralLogger(Request.Path.ToString(),
Request.UrlReferrer);
}
And now, every time the ASP.Net engine displays a file its referral information will be stored in your database.
Tuesday, July 22, 2008
the future is dynamic with Python
Dynamic Injector Mechanism
The compilation model for dynamic languages enables you to use simple syntax into which additional code is injected at run time. For example, you might have code that reads a value from the query string. The URL for the page might look like this:
http://someserver/somepage.aspx?MyValue=17
In a C# page, you can use the following code to obtain the value:
String myValue = Request.QueryString["MyValue"];
The dynamic injector mechanism allows you to write much simpler code in dynamic languages, as shown in the following examples:
myVar = Request.MyValue
The support code for dynamic languages enables the registration of an object referred to as an injector. By registering as an injector, the object agrees to handle code that matches a certain pattern. For example, if the dynamic language engine is unable to resolve the expression SomeObj.SomeName, where SomeObj is an HttpRequest object and SomeName is not a real property of the HttpRequest object, the engine calls the injector that has been registered to handle that pattern. The injector handles the expression by calling SomeObj.QueryString["SomeString"]. The net effect is exactly the same, but the syntax is much cleaner.
The injector mechanism has many potential uses. For example, wherever you would write SomeControl.FindControl("SomeChildControl") in C#, you can write SomeControl.SomeChildControl in a dynamic language application. The mechanism is extensible and can be applied to any collection that is indexed by strings.
Friday, March 16, 2007
remoting error: internal server error occured .net 2.0. programatically turn off customerrorsmode
Thursday, March 15, 2007
user(programmer)-friendly control events: how to prevent NullReferenceException error message in custom control events
VB.NET:
If Save IsNot Nothing Then RaiseEvent Save(sender, e)
C#:
if (Save == null) Save(sender, e);
/* you want to raise an event and if the event is not hooked by your usercontrol's users, you want the program to handle it gracefully (no annoying NullReferenceException error messages), here's how: */
public partial class FormRefenceTemplate : Form
{
/*
public delegate void SaveEventHandler(object sender, EventArgs e);
public event SaveEventHandler Save;
*/
// public delegate void TaskEventHandler(object sender, EventArgs e);
// public event TaskEventHandler Save, Open, LoadAll, UndoAll, Print, Help;
/* the following is way much better, we don't want to create our own handler (the commented TaskEventHandler) since there is no need for us to pass/receive additional information(read: custom EventArgs) from the events, just use the default EventArgs */
public event EventHandler Save = notImplemented, LoadAll = notImplemented, UndoAll = notImplemented, Print = notImplemented, Help = notImplemented;
static EventHandler notImplemented = delegate(object sender, EventArgs e)
{
MessageBox.Show("Not yet implemented", "", MessageBoxButtons.OK, MessageBoxIcon.Stop);
};
private void cmdSave_Click(object sender, EventArgs e)
{
// if (sender != null) // no need for this line or in putong-wa: "bu yong" :)
Save(sender, e);
}
}
--------
that's it, just point the event variable to a static delegate
Tuesday, March 13, 2007
Monday, January 15, 2007
Sunday, January 14, 2007
some weird postgresql server setup
postgresql 8.2.1 works in lower version (8.1.1.1) -- psqlodbc-08_01_0101.zip
Wednesday, December 20, 2006
Bleeping Computer - rundl132.exe - File Information
Filename: rundl132.exe
Command: C:\Windows\rundl132.exe
Description: Added by the W32/Looked-A EXE virus.
File Location: %WinDir%
Startup Type: This program uses either the Load= entry in the win.ini or the registry key HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Load to load the program."
Slashdot | Google Deprecates SOAP API
So is that why nerds are getting acused of rape? (Not checking return codes...)
The semicolons should be double ampersands, so that execution will stop if a command fails."
O'Reilly Radar > Google Deprecates Their SOAP Search API
Wednesday, December 13, 2006
How To Change The Screen Resolution in C#
By Joshy George
Introduction
This is a sample program that will demonstrate how to change resolution at runtime.
All programmers are facing common problem is how to change screen Resolution dynamically. In .Net 2005 it's very easy to change the screen resolution. Here I will explain you how can we get the Screen resolution and how we will change the resolution at dynamically and while unloading the page it will come as it was before. In dot net we can access the values of user's screen resolution through the Resolution class. It also affects all running (and minimized) programs.
Important Functions
No Functions
Page_Load
Screen Srn = Screen.PrimaryScreen;
tempHeight = Srn.Bounds.Width;
tempWidth = Srn.Bounds.Height;
Page.ClientScript.RegisterStartupScript(this.GetType(), "Error", "");
//if you want Automatically Change res.at page load. please uncomment this code.
if (tempHeight == 600)//if the system is 800*600 Res.then change to
{
FixHeight = 768;
FixWidth = 1024;
Resolution.CResolution ChangeRes = new Resolution.CResolution(FixHeight, FixWidth);
}
Change Resoultion switch (cboRes.SelectedValue.ToString())
{
case "800*600":
FixHeight = 800;
FixWidth = 600;
Resolution.CResolution ChangeRes600 = new Resolution.CResolution(FixHeight, FixWidth);
break;
case "1024*768":
FixHeight = 1024;
FixWidth = 768;
Resolution.CResolution ChangeRes768 = new Resolution.CResolution(FixHeight, FixWidth);
break;
case "1280*1024":
FixHeight = 1280;
FixWidth = 1024;
Resolution.CResolution ChangeRes1024 = new Resolution.CResolution(FixHeight, FixWidth);
break;
}
Thursday, December 07, 2006
[GENERAL] Turning off triggers ? 25-Nov-02
Another issue with bulk loading is triggers firing with each row inserted. If you are sure your data is trustworthy and already meets your referential integrity requirements, you can turn off triggers for the bulk load and turn them back on immediately afterward. You should not use this option when your data is not completely clean.
The reltriggers field in the pg_class table contains the number of triggers active for each table. It can be set to 0 the disable the triggers, but will need to be reset to the proper number of triggers to have them re-enabled.
UPDATE 'pg_class' SET 'reltriggers' = 0 WHERE 'relname' = 'tablename';
UPDATE pg_class SET reltriggers = (
SELECT count(*) FROM pg_trigger where pg_class.oid = tgrelid)
WHERE relname = 'table name';
Contributors: Glen Eustace geustace at godzone.net.nz, Stephan Szabo"
Wednesday, December 06, 2006
should this blog still be called .NET Webservices?
-----------------------------
the proxy(stub) code for middletier
using System;
using System.Data;
namespace SyerDll
{
public abstract class RemoteObjectDef : MarshalByRefObject
{
public abstract string Test();
public abstract DataSet ReturnHeader();
}
}
----------------------------------
-----------------------------
sample Client Code:
using System;
using System.Data;
using SyerDll;
class Mate
{
public static void Main()
{
Console.WriteLine("Creating Remote Object.");
string url = "tcp://192.168.10.254:8076/RemoteObjectXXX";
/*RemoteObjectDef ro = (SyerDll.RemoteObjectDef)Activator.GetObject(
typeof(SyerDll.RemoteObjectDef), url );*/
RemoteObjectDef ro = (SyerDll.RemoteObjectDef)Activator.GetObject(
typeof(SyerDll.RemoteObjectDef), url );
DataSet rs = ro.ReturnHeader();
for(int i = 0; i < rs.Tables[0].Rows.Count; i++)
Console.WriteLine(rs.Tables[0].Rows[i]["Lastname"].ToString());
Console.WriteLine("Remote Object says " + ro.Test() );
}
}
-----------------------------------------
sample Server Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using SyerDll;
using System.Data;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;
namespace TheServer
{
public class RemoteObject : SyerDll.RemoteObjectDef
{
public override string Dancer()
{
return "UMD";
// throw new Exception("The method or operation is not implemented.");
}
public override DataSet ReturnHeader()
{
DataSet ds = new DataSet();
DataTable t = new DataTable();
t.Columns.Add("Lastname", typeof(string));
t.Rows.Add("Lennon");
t.Rows.Add("McCartney");
t.Rows.Add("Harrison");
t.Rows.Add("Starr");
// ds.Tables[0].Rows[0][0]
ds.Tables.Add(t);
return ds;
//throw new Exception("The method or operation is not implemented.");
}
public override string Test()
{
return "Hello mike" + DateTime.Now.ToString();
// throw new Exception("The method or operation is not implemented.");
}
static void Main(string[] args)
{
// Set up the configuration parameters through a dictionary
IDictionary properties = new Hashtable();
properties.Add("port", 8076);
properties.Add("secure", false);
// properties.Add("impersonate", false);
// Create an instance of a channel
TcpServerChannel serverChannel =
new TcpServerChannel(properties, null);
ChannelServices.RegisterChannel(serverChannel,false);
// ChannelServices.RegisterChannel(new TcpChannel(8076));
Type RemoteType = Type.GetType("TheServer.RemoteObject");
// RemotingConfiguration.RegisterWellKnownServiceType(RemoteType, "RemoteObjectXXX", WellKnownObjectMode.SingleCall);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(TheServer.RemoteObject), "RemoteObjectXXX", WellKnownObjectMode.SingleCall);
//while(true)
Console.WriteLine("Michael Buen");
Console.ReadLine();
}
}
}
Saturday, December 02, 2006
restore postgresql database
copy the whole c:\program files\postgresql
:D
then copy to other computer, set the necessary permission(note: NTFS) , like the windows username: postgres-acct. note that postgres-su (superuser), has no bearing in windows usernames, you must not look for this user
Friday, December 01, 2006
A '100% .NET application' is one that only uses the APIs defined under the System namespace and does not use P/Invoke. These applications would in theory run unmodified on Windows, Linux, HP-UX, Solaris, MacOS X and others. Note that this requirement also holds for all assemblies used by the application. If one of them is Windows-specific, then the entire program is not a 100% .NET application. Furthermore, a 100% .NET application must not contain non-standard data streams in the assembly. For example, Visual Studio .NET will insert a #- stream into assemblies built under the 'Debug' target. This stream contains debugging information for use by Visual Studio .NET; however, this stream can not be interpreted by Mono (unless you're willing to donate support). Thus, it is recommended that all Visual Studio .NET-compiled code be compiled under the Release target before it is executed under Mono."
Howto Backup PostgreSQL Databases | nixCraft
Howto Backup PostgreSQL Databases
Posted by LinuxTitli in Linux, Howto, UNIX, Data recovery, Backup
I rarely work on PostgreSQL database. Recently I had received a request to backup PostgreSQL databases as one of our client want to reformat server. PostgreSQL is a one of the robust, open source database server. Like MySQL database server, it also provides utilities for creating backup.
Login as a pgsql user$ su - pgsqlGet list of database(s) to backup$ psql -lBackup database using pg_dump command. pg_dump is a utility for backing up a PostgreSQL database. It dumps only one database at a time. General syntax:
pg_dump databasename > outputfile
To dump a payroll database:$ pg_dump payroll > payroll.dump.outTo restore a payroll database:$ psql -d payroll -f payroll.dump.outOR$ createdb payrollHowever, in real life you need to compress database:
$ psql payroll $ pg_dump payroll | gzip -c > payroll.dump.out.gzTo restore database use the following command:$ gunzip payroll.dump.out.gzHere is a shell script for same task:
$ psql -d payroll -f payroll.dump.out#!/bin/bashAnother option is use to pg_dumpall command. As a name suggest it dumps (backs up) each database, and preserves cluster-wide data such as users and groups. You can use it as follows:
DIR=/backup/psql
[ ! $DIR ] && mkdir -p $DIR || :
LIST=$(psql -l | awk '{ print $1}' | grep -vE '^-|^List|^Name|template[0|1]')
for d in $LIST
do
pg_dump $d | gzip -c > $DIR/$d.out.gz
done$ pg_dumpall > all.dbs.outOR$ pg_dumpall | gzip -c > all.dbs.out.gzTo restore backup use the following command:$ psql -f all.dbs.out postgresReferences:
Wednesday, November 29, 2006
No buffer space available Fix (affected program: PostgreSQL for windows)
Restart your computer, if all goes well then you fixed the problem, if not, revert the changes by restoring the registry. (You may have to reboot to safe mode to do this)."