When developing web-enabled applications you often want to test their behaviour in different browser-versions.
Today I found a tool which enables you to test your application output on Internet Explorer versions 3, 4.01, 5.01, 5.5 and 6.0. Very handy. Download it at http://tredosoft.com/Multiple_IE.
25 October 2007
09 July 2007
Get the corresponding day name from a date
In this article I'll discuss how to get the localized desciptive name of a day. Earlier I checked the daynumber and converted it to the description with a Select Case statement:
Dim d As Date = Date.Now
Dim s As String = Nothing
Select Case d.DayOfWeek
Case DayOfWeek.Monday
s = "Maandag"
Case DayOfWeek.Tuesday
s = "Dinsdag"
........
End Select
Get the non localized description
I'm writing this article on the 9th of july in the year 2007. This is on monday. The date class in the .NET framework has a property with which you can read the description of a day. This can be done with few lines of code:
Dim d As Date = Date.Now
Dim s As String = Nothing
s = d.DayOfWeek
The string variable s will now be filled with the value "Monday".
Get the localized description
To get the localized description you can use the following code:
Dim d As Date = Date.Now
Dim s As String = Nothing
Dim dtfi As System.Globalization.DateTimeFormatInfo = New System.Globalization.CultureInfo("nl-NL").DateTimeFormat
s = dtfi.GetDayName(d)
As you can see we localized a DateTimeFormatInfo. We're using this to GetDayName of the date. I used the dutch ISO countrycode "nl-NL" so the string will be populated with "Maandag".
Dim d As Date = Date.Now
Dim s As String = Nothing
Select Case d.DayOfWeek
Case DayOfWeek.Monday
s = "Maandag"
Case DayOfWeek.Tuesday
s = "Dinsdag"
........
End Select
Get the non localized description
I'm writing this article on the 9th of july in the year 2007. This is on monday. The date class in the .NET framework has a property with which you can read the description of a day. This can be done with few lines of code:
Dim d As Date = Date.Now
Dim s As String = Nothing
s = d.DayOfWeek
The string variable s will now be filled with the value "Monday".
Get the localized description
To get the localized description you can use the following code:
Dim d As Date = Date.Now
Dim s As String = Nothing
Dim dtfi As System.Globalization.DateTimeFormatInfo = New System.Globalization.CultureInfo("nl-NL").DateTimeFormat
s = dtfi.GetDayName(d)
As you can see we localized a DateTimeFormatInfo. We're using this to GetDayName of the date. I used the dutch ISO countrycode "nl-NL" so the string will be populated with "Maandag".
Labels:
2.0,
date,
description,
dutch,
format,
localization
29 June 2007
Alternative for SmartNavigation in VS2003
When building an application you want to maintain the position and the focus of a control on the screen when a postback occures. Microsoft gives you the opportunity to use SmartNavigation. The problem with SmartNavigation is that is does not always work very well.
This article describes an alternative method to maintain to position and the focus of a control by using some code. The solution is very simple. De code provided in this article is in C# code.
We have to put some code in the Global.asax so that it is accessible easily in your application.
public class Global : System.Web.HttpApplication
{
// insert static SetFocus method here, just below the class Global declaration:
public static void SetFocus(System.Web.UI.Page webPage)
{
string[] pbCtrl = webPage.Page.Request.Form.GetValues("__EVENTTARGET");
if (pbCtrl != null && pbCtrl.Length > 0)
{
string ctrlId;
ctrlId = pbCtrl[0];
System.Web.UI.Control ctrlFound = webPage.Page.FindControl(ctrlId);
if ((ctrlFound != null) &&
(
ctrlFound is System.Web.UI.WebControls.DropDownList
ctrlFound is System.Web.UI.WebControls.TextBox
ctrlFound is System.Web.UI.WebControls.RadioButton
ctrlFound is System.Web.UI.WebControls.RadioButtonList))
{
string ctrlClientId;
ctrlClientId = ctrlFound.ClientID;
string strScript;
strScript = "<SCRIPT language=\"javascript\"> document.getElementById('"
+ ctrlClientId + "').focus(); document.getElementById('"+ ctrlClientId
+ "').scrollIntoView(true) </SCRIPT>";
webPage.Page.RegisterStartupScript("controlFocus",strScript );
}
}
}
To use the code displayed above in a page you need to call the SetFocus method. You have to call this method when a postback occures. You need to call this function in the Page_Load event.
private void Page_Load(object sender, System.EventArgs e)
{
if(IsPostBack)
{
Global.SetFocus(this);
}
}
This article describes an alternative method to maintain to position and the focus of a control by using some code. The solution is very simple. De code provided in this article is in C# code.
We have to put some code in the Global.asax so that it is accessible easily in your application.
public class Global : System.Web.HttpApplication
{
// insert static SetFocus method here, just below the class Global declaration:
public static void SetFocus(System.Web.UI.Page webPage)
{
string[] pbCtrl = webPage.Page.Request.Form.GetValues("__EVENTTARGET");
if (pbCtrl != null && pbCtrl.Length > 0)
{
string ctrlId;
ctrlId = pbCtrl[0];
System.Web.UI.Control ctrlFound = webPage.Page.FindControl(ctrlId);
if ((ctrlFound != null) &&
(
ctrlFound is System.Web.UI.WebControls.DropDownList
ctrlFound is System.Web.UI.WebControls.TextBox
ctrlFound is System.Web.UI.WebControls.RadioButton
ctrlFound is System.Web.UI.WebControls.RadioButtonList))
{
string ctrlClientId;
ctrlClientId = ctrlFound.ClientID;
string strScript;
strScript = "<SCRIPT language=\"javascript\"> document.getElementById('"
+ ctrlClientId + "').focus(); document.getElementById('"+ ctrlClientId
+ "').scrollIntoView(true) </SCRIPT>";
webPage.Page.RegisterStartupScript("controlFocus",strScript );
}
}
}
To use the code displayed above in a page you need to call the SetFocus method. You have to call this method when a postback occures. You need to call this function in the Page_Load event.
private void Page_Load(object sender, System.EventArgs e)
{
if(IsPostBack)
{
Global.SetFocus(this);
}
}
26 June 2007
Ask for confirmation
When users delete information it's often a requirement that they give a confirmation. This can be implemented with little client-side javascript coding. In this example I'll work this out.
First add a new Web Form to your Webapplication and drag a .NET Button control on the form. We will name the Text property of this Button Control "Delete" and go to the codebehind of the Page.
Add the following code in the Page_Load event:
Button1.Attributes.Add("onClick", "return confirm('Are you sure?');")
Now run the application and click on the Delete button. The user will be prompted with a nice client-side confirmation box.
First add a new Web Form to your Webapplication and drag a .NET Button control on the form. We will name the Text property of this Button Control "Delete" and go to the codebehind of the Page.
Add the following code in the Page_Load event:
Button1.Attributes.Add("onClick", "return confirm('Are you sure?');")
Now run the application and click on the Delete button. The user will be prompted with a nice client-side confirmation box.
When the user clicks cancel the Form will not be posted back to the server. This will only happen when the user clicks the OK button.
23 June 2007
Using the .NET Connector for SAP
Many enterprise organizations use SAP for their business critical processes. Application written in .NET often require data stored in SAP systems. In this article I'd like to present the interoperability between a .NET application and a SAP system using the .NET connector for SAP.
Installing the .NET Connector for SAP
First of all we need a plugin for Visual Studio.NET 2003. This software can be downloaded at the SAP website. Download the 2.0.1 version. You'll need a service account for this. Typically the SAP administrators in your organization can supply you with one. The Connector software is only available for Visual Studio.NET 2003 and thus will not work with Visual Studio 2005. In this example we're going to compile an assembly with the connector functionality and use this assembly in a 2005 solution.
Click here to download the .NET Connector for SAP
Create the .NET assembly
After downloading and installing the software start Visual Studio.NET 2003. Notice the SAP Connector plugin in the splash screen or in the Help, Info screen.

Create a new project (File, New, Project) of the type Empty Project. Add a new item to the project of the type SAP Connector.

Proxy and 2 references (SAP.Connector and SAP.Connector.Rfc) will be added to the solution.

Open the Proxy we just created and open the Server Explorer. Notice that there's a new node available named SAP. Right click on the Application Servers node and choose Add Application Server. The "Add new SAP Application Server" window opens. Fill in the following settings:
Drag and drop a function on the opened SAP Proxy file. In this example we'll use the standard BAPI called Bapi_Salesorder_Getlist. Compile the project and congratulations, you just finished the second step by creating an assembly.
Let's interact with SAP!
Start Visual Studio 2005 and create a new webproject. Add references to the compiled assembly and to the in step 1 installed SAP.Connector and SAP.Connector.Rfc.
Create a new Web Form and supply this webform with a GridView. On the Page_Load event use the following code.

Run the application and you'll see that the information is extracted from the SAP system and shown in the GridView.
Installing the .NET Connector for SAP
First of all we need a plugin for Visual Studio.NET 2003. This software can be downloaded at the SAP website. Download the 2.0.1 version. You'll need a service account for this. Typically the SAP administrators in your organization can supply you with one. The Connector software is only available for Visual Studio.NET 2003 and thus will not work with Visual Studio 2005. In this example we're going to compile an assembly with the connector functionality and use this assembly in a 2005 solution.
Click here to download the .NET Connector for SAP
Create the .NET assembly
After downloading and installing the software start Visual Studio.NET 2003. Notice the SAP Connector plugin in the splash screen or in the Help, Info screen.

Create a new project (File, New, Project) of the type Empty Project. Add a new item to the project of the type SAP Connector.

Proxy and 2 references (SAP.Connector and SAP.Connector.Rfc) will be added to the solution.

Open the Proxy we just created and open the Server Explorer. Notice that there's a new node available named SAP. Right click on the Application Servers node and choose Add Application Server. The "Add new SAP Application Server" window opens. Fill in the following settings:
- DestinationType: Custom Login Settings
- Client: The SAP logon client
- Username: The SAP Logon user
- Password: The SAP Logon password
- AppServerHost: The IP Address or Hostname of the SAP system
- SystemNumber: The R/3 system number
Drag and drop a function on the opened SAP Proxy file. In this example we'll use the standard BAPI called Bapi_Salesorder_Getlist. Compile the project and congratulations, you just finished the second step by creating an assembly.
Let's interact with SAP!
Start Visual Studio 2005 and create a new webproject. Add references to the compiled assembly and to the in step 1 installed SAP.Connector and SAP.Connector.Rfc.
Create a new Web Form and supply this webform with a GridView. On the Page_Load event use the following code.

Run the application and you'll see that the information is extracted from the SAP system and shown in the GridView.
Subscribe to:
Posts (Atom)