In one of my web application, ItemCommand event of a datagrid doesn't fire as expected. After some work, I find out the reason.
The bind to datasouce code of this datagrid control is put in Page_PreRender handler, not in Page_Load. On first load of the page, everything is fine, the rows are populated in datagrid and I add "cancel" button for each row.
Then I click "cancel" button, which trigger a postback. Again, Page_Load hander runs first. Then .NET framework try to call ItemCommand event, I reckon it checks the rows in datagrid and since their are no rows yet. It decides not to call ItemCommand. Then Page_PreRender is called. The command is ignored.
So, don't do important tasks in Page_PreRender
Showing posts with label 信息技术. Show all posts
Showing posts with label 信息技术. Show all posts
Thursday, May 1, 2008
Use custom control in Page_Load
As known, custom control's onload() method is called after container's page_load event fires. So in Page_Load handler, custom control hasn't been fully initialized. Although we can do something on custom control in prerender handler, but sometimes we need custom control ready before anything else can do.
Here is an example:
If we have an authenticate custom control and we want everything else run after check the permission of user, we have to make sure custom control is ready. But since onload hasn't been invoked, the codes in it hasn't been executed yet.
The work around is put all code in onload to anothe method, then call it directly from container page's Page_Load handler.
Here is an example:
If we have an authenticate custom control and we want everything else run after check the permission of user, we have to make sure custom control is ready. But since onload hasn't been invoked, the codes in it hasn't been executed yet.
The work around is put all code in onload to anothe method, then call it directly from container page's Page_Load handler.
Tuesday, April 29, 2008
How to prevent Post back event when page refresh
One annoying behavior of ASP.NET pages is a replay of postback events when user hit refresh (F5) in browser.
This behavior is easily reproducible:
Place ASP button on Web Form
1. Add some code to Button_Click event
2. View page in browser
3. Check that your code being executed when you hit button
4. Refresh page and observe that your code being executed once again
The are a couple of solutions to get around this. But the easiest way is like this,
At the end of eventhandler, ie. button click, itemcommand, insert a line of code.
Response.Redirect("thispage.aspx ");
Which means, just redirect to the same page.
Also, this can be used to disable Back button
Eric
This behavior is easily reproducible:
Place ASP button on Web Form
1. Add some code to Button_Click event
2. View page in browser
3. Check that your code being executed when you hit button
4. Refresh page and observe that your code being executed once again
The are a couple of solutions to get around this. But the easiest way is like this,
At the end of eventhandler, ie. button click, itemcommand, insert a line of code.
Response.Redirect("thispage.aspx ");
Which means, just redirect to the same page.
Also, this can be used to disable Back button
Eric
Monday, April 7, 2008
Error when installing .NET Framework 3.0
Microsoft .NET Framework 3.0 has encountered a problem during setup.
Setup did not complete correctly.
occured while installing the .NET 3.0 redistrubutable (downloaded from here) on my PC running XP Pro SP (also with .NET 1.1 & 2.0).
After some investigation it turns out this error was caused when installing the WCF (Windows Communication Foundation) components - when trying to open the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Security\ServiceModel 3.0.0.0
I thought this was odd, because my user is a local admin - so in regedit (regedt32) I tried giving my user permissions to full control of this registry node... then reran the install - however to no avail - same error.
So, tried giving Everyone full control of this node - reran the install - and bingo, it worked!
For those of you who don't know - here's how:
1. Open the registry editor: Start - Run..., then enter "regedt32" (without quotes).
2. Navigate down to the node by opening each node in the heirarchy.
3. Right click on the node we're after (ServiceModel 3.0.0.0) and select Permissions
4. Click on Add, then enter "everyone" (no quotes) on the 'Select Users, Computers or Groups' dialog then click OK.
5. Back on the 'Permissions for ServiceModel 3.0.0.0' dialog select the user group Everyone, then make sure the Full Control checkbox has a tick, then click OK.
Thats it - now rerun the .NET 3.0 installation.
Setup did not complete correctly.
occured while installing the .NET 3.0 redistrubutable (downloaded from here) on my PC running XP Pro SP (also with .NET 1.1 & 2.0).
After some investigation it turns out this error was caused when installing the WCF (Windows Communication Foundation) components - when trying to open the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Security\ServiceModel 3.0.0.0
I thought this was odd, because my user is a local admin - so in regedit (regedt32) I tried giving my user permissions to full control of this registry node... then reran the install - however to no avail - same error.
So, tried giving Everyone full control of this node - reran the install - and bingo, it worked!
For those of you who don't know - here's how:
1. Open the registry editor: Start - Run..., then enter "regedt32" (without quotes).
2. Navigate down to the node by opening each node in the heirarchy.
3. Right click on the node we're after (ServiceModel 3.0.0.0) and select Permissions
4. Click on Add, then enter "everyone" (no quotes) on the 'Select Users, Computers or Groups' dialog then click OK.
5. Back on the 'Permissions for ServiceModel 3.0.0.0' dialog select the user group Everyone, then make sure the Full Control checkbox has a tick, then click OK.
Thats it - now rerun the .NET 3.0 installation.
Wednesday, December 19, 2007
NuSoap notice
1. Put all defination of complex type into one file
2. When use .net application to call Nusoap web service, use wsdl.exe instead of add web reference to create proxy class
2. When use .net application to call Nusoap web service, use wsdl.exe instead of add web reference to create proxy class
Sunday, November 4, 2007
MySql commands
1. mysql -h localhost -u root -p
2. dump database
mysqldump -h localhost -u root -p DBNAME>c:\dumpfile.sql
3. restore database
mysql -h localhost -u root -p DBNAME<c:\dumpfile.sql
2. dump database
mysqldump -h localhost -u root -p DBNAME>c:\dumpfile.sql
3. restore database
mysql -h localhost -u root -p DBNAME<c:\dumpfile.sql
Sunday, September 30, 2007
Five free Web apps we can't live without
Ta-da List
PBWiki
Google Docs
Bloglines V3
Zoho Creator
http://www.computerworld.com/action/article.do?command=printArticleBasic&articleId=9038638
PBWiki
Google Docs
Bloglines V3
Zoho Creator
http://www.computerworld.com/action/article.do?command=printArticleBasic&articleId=9038638
Thursday, September 20, 2007
Three internet platform
http://blog.pmarca.com/2007/09/the-three-kinds.html
Thursday, September 13, 2007
Using JavaScript Along with ASP.NET
http://msdn2.microsoft.com/en-us/library/aa479011.aspx
Monday, July 16, 2007
Export more than 255 characters into Excel by OLEDB
I create a excel using ole db provider, like below
string connString = "Data Source=" + fullPath + "; Provider=Microsoft.Jet.OLEDB.4.0; Extended Properties=Excel 8.0;";
OleDbConnection myConn=new OleDbConnection(connString);
OleDbCommand myCommand=new OleDbCommand();
myCommand.CommandText = "CREATE TABLE Report (msisdn string, comment string )";
// connect an excel file, if this file doesn't exist, it will be created
myConn.Open();
// create a workbook in this file
myCommand.ExecuteNonQuery();
The problem is when import more than 255 characters into Excel, error occurs:
OLEDBException: The field is too small to accept the amount of data you attempted to add.....
This is because string in Excel has the limitation of 255 characters. To work around this, change the datatype to memo
myCommand.CommandText = "CREATE TABLE Report (msisdn string, comment memo)";
string connString = "Data Source=" + fullPath + "; Provider=Microsoft.Jet.OLEDB.4.0; Extended Properties=Excel 8.0;";
OleDbConnection myConn=new OleDbConnection(connString);
OleDbCommand myCommand=new OleDbCommand();
myCommand.CommandText = "CREATE TABLE Report (msisdn string, comment string )";
// connect an excel file, if this file doesn't exist, it will be created
myConn.Open();
// create a workbook in this file
myCommand.ExecuteNonQuery();
The problem is when import more than 255 characters into Excel, error occurs:
OLEDBException: The field is too small to accept the amount of data you attempted to add.....
This is because string in Excel has the limitation of 255 characters. To work around this, change the datatype to memo
myCommand.CommandText = "CREATE TABLE Report (msisdn string, comment memo)";
Subscribe to:
Posts (Atom)