Tuesday, March 01, 2005

dropdownlist databind error

The following error

ASP.NET dropdownlist Specified argument was out of the range of valid values. Parameter name: value

will occur if

1) Set a dropdownlist selectedvalue to some value - e.g. 123
2) Bind the dropdownlist to a datasource which does not contain the value 123

Solution:
Before binding, extract the selected value. Set dropdownlist.selectedvalue to nothing, then after binding, reinsert the value back. (Does not work if set dropdownlist.items.clear or setting selectedindex to -1)

Or correctly, should bind first, then assign selectedvalue




Monday, February 28, 2005

Datagrid Sorting

The following link provide lots of articles on web datagrid - http://www.datagridgirl.com/articles.aspx

To handle sorting on datagrid

1) Datagrid properties - allowsorting = true

2) Edit html to add the following code in asp:datagrid tag
allowpaging="True" onsortcommand="dgdList_SortCommand"

3) Do an event handler

Sub dgdList_SortCommand(ByVal Source As Object, ByVal E As DataGridSortCommandEventArgs) Handles dgdList.SortCommand
sortExpression = " ORDER BY " & E.SortExpression
BindGrid()
End Sub


4) BindGrid
In bindgrid procedure, remember to pass the sortExpression to the SQL statement


Saturday, February 26, 2005

Asp.net IIS error

It is an error to use a section registered as
allowDefinition='MachineToApplication' beyond application level. This
error can be caused by a virtual directory not being configured as an
application in IIS


Steps resulting in above error when running web application

1) Web project was created in another PC and copied to another.
2) Put project in wwwroot directory
3) Using IIS - created an web directory pointing to this project.

Solution:
4) In IIS - should just navigate to the project folder and right click to create an application.

Wednesday, February 23, 2005

One Click Button Export to Excel

Have adapted the following code to export dataset to excel

http://prashantnayak.freeservers.com/Download/ExportButton.html

OO Design

I have this requirement - whenever user add an transaction, it will trigger an Email Notification. The problem is where to put this Email Notification
- in add transaction class (separate library from web application)- when the transaction is added successfully?
- in the web application controller ?
- in the code-behind of that web page?

If I put in Add Transaction class, it means whenever this feature is called, the Email is definitely triggered. What happens if another module uses this feature but does not need to trigger Email? I was thinking of using delegate and pass in the notification function.

However, triggering of Email uses SMTP, which logically should resides in web application page.

In the end, I build in the email notification (but without actual trigger of email) in add transaction class, and in the web application to trigger the actual email.

So if another function uses the same feature, it has to manually trigger the email, but at least the email contents are already set in the Add Transaction class.

Wednesday, February 16, 2005

ASP.Net Custom Error

Keep hitting unable to debug when I set custom error to 'ON' and running the application through the start button.

Therefore, I have two web.config file - webLocal.config and webRemote.config

For localhost - I turn customerror to off, debug to true
For remote - I build the application in release mode, debug to false, customerror to remoteonly , this is supposed to be better secured.

Monday, February 07, 2005

SMTP

Found this great web site http://www.systemwebmail.com/ which contains all the FAQ on SMTP in dotnet.

Previously, I encounter problem sending mail from SMTP server in my asp.net application. The reason being I have selected an SMTP server which does not allow relaying. After I set to the correct SMTP, I have no problem sending email.

This is my code

Dim mail As New MailMessage
mail.From = "yourname@email.com"
mail.To = "cust@123.com"
mail.Subject = "some subject"
mail.Priority = MailPriority.High
mail.BodyFormat = MailFormat.Text
mail.Body = "some message"



Try
SmtpMail.SmtpServer = "mail server ip address" //put ip address here
SmtpMail.Send(mail)
Catch ex As Exception
Throw ex
End Try



FTP download (VB.Net)

Have downloaded a FTP class written in VB.Net

This class is great, it allows login, change directory, creation of new directory, ftp upload and ftp download.

Basically, my client just need to call this ftp class, login and upload data.

The FTP site is located in the web server, thus my remote server will transmit file to this ftp server.

After that the client will download the file from the web server using Current.Response.WriteFile

Saturday, January 29, 2005

FTP download

I am trying to write a program to download Excel file from a remote server to client's browser.

Initially I thought of setting a shared drive in web server, pointing to the remote server. But our web server is actually considered a public server, that should not have any mapping to the remote server, which is our inhouse internal server. Make any sense? Not sure what I am talking also.

Anyway, the solution is to write an FTP class, that will download data from remote server to the browser. Also know that there are 2 kinds of downloading - ftp and http. FTP is actually slower than HTTP.

I found an FTP class which is written in C#. Unfortunately, our company's program is written in Vb.net. Actually I would rather use C# because it is much more an elegant language, and I studied C# in Microsoft.Net. Well due to time constraint, I am thinking of just compiling the C# class into a library and used it.

For one thing, I dont have the luxury to convert the C# class to vb.net.
Secondly, I don't know if the codes work yet, no point wasting my time converting.

Anyway, if it is usable, I will convert it eventually, not sure when though...