Monday, August 18, 2008

SCRIPTSTER. East Java Baker: GridView Delete, with Confirmation

SCRIPTSTER. East Java Baker: GridView Delete, with Confirmation: "protected void GridView1_RowDataBound object sender,

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

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
IronPython

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

Thursday, March 15, 2007

user(programmer)-friendly control events: how to prevent NullReferenceException error message in custom control events

tired of checking for null values from event variables?

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

Monday, January 15, 2007