|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
#1
|
||||
|
||||
|
Coding Tips For .NET
1) It is better to use Flow Control Layout, rather then Grid Control Layout when creating Web Applications in ASP.NET. Why, you ask??? The Grid Control uses absolute style positioning and sizing of controls, which isn't supported on all browsers.
2) When using a DataGrid that is non-editable and using column templates, don't setup any EditItemTemplate tag on any of the columns. THis add unneeded overhead to the grid. Also when using Bound Columns with your DataGrid (non-templated columns) and you are not going to be editing through the grid itself, make all of your columns ReadOnly. THis will alter the HTML that is generated to make it much "thinner" by no adding label controls for each cell of the table. 3) Append strings with & or &= instead of + or +=. The difference is when you try to append something that isn't a string. & will work + won't. 4) Use AndAlso and OrElse instead of just AND or OR. When performing an If statement in VB.NET, VB actually evaluates both expressions to see if the who expression is true. Even when the first expression is false. It continues to look at the second argument even though it doesn't have to. This very helpful when using Functions as expressions in the statemtn Code:
Instead of doing this If(Function1() And Function2()) Then Do this If(Function1() AndAlso Function2()) Then The first code will evaluate the result of Function2(), even if Function1() returned false. The second will only evaluate Function2() if Function1() returned true. 5) Don't use Labels on a web form unless it is going to be referenced in code (changing the text or making it invisible). If the it will contain static (unchanging) text, just type it directly into the page. There's no sense in adding unnecessary overhead to your applications. 6) It is 5-6 times faster to compare the Length of a string, than it is checking for "" or NOT "" Example: Code:
Instead of doing this If(txtName.Text = "") Then Do this If(Len(txtName.Text) = 0) Then Or If txtName.Text.Length = 0 Then 7) Avoid using Response.Write in ASP.NET. The ASP.NET rendering process takes place after the Response.Write would, you have no control over where the data is written to on the page (It appears at the top of the page, even above you <HTML> tag). 8) Use the Parse functions instead of CInt, CDbl, CSng, CBool, etc... The <datatype>.Parse commands are about twice as fast as their equivalent C converted commands when dealing with strings. Example: Code:
Dim strTemp As String = "123456" Dim intValue As Integer Instead of doing this intValue = CInt(strTemp) Do this intValue = Integer.Parse(strTemp) 9) Avoid using empty Try...Catch blocks. Not placing code in the Catch area of the Try...Catch block is essentially the same as saying "On Error Resume Next", which can be a bad thing, especially for debugging purposes. 10) Avoid using RegisterStartupScript. This adds unnecesarry processing on the web server for handling things that should have been done in the client (like form validation). Instead use either client-side javascript or .NET's Validator controls (Compare, Custom, Required Field, Regular Expression) Last edited by Memnoch : April 18th, 2005 at 06:27 PM. |
|
#2
|
|||
|
|||
|
6) It is 5-6 times faster to compare the Length of a string, than it is checking for "" or NOT ""
Instead of doing this If(txtName.Text = "") Then Do this If(Len(txtName.Text) = 0) Then its also significantly faster to avoid the vb compatability namespace |
|
#3
|
|||
|
|||
|
Flow and Grid control layout
What is the difference between flow and grid control layout?
How can I set my web appliction to use one of the two layouts? thanks |
|
#4
|
||||
|
||||
|
The difference is Grid Control layout uses absolute style positioning and sizing of controls, which isn't supported on all browsers.
The default is Grid Control Layout. The documents pageLayout property. |
|
#5
|
|||
|
|||
|
Code in aspx or aspx.vb
I have a query ...I am a beginner
want to know that for ASP.NET programming the code should be written in test.aspx page or in test.aspx.vb page and why? |
|
#6
|
||||
|
||||
|
post your question in it's own separate thread.
|
|
#7
|
|||
|
|||
|
11: if using structured error handling, close your database connection in the FINALLY block. this ensures the connection gets closed in all cases.
c# ex: Code:
try
{
//connect to DB, do stuff
oConn.Close(); //optional - will not cause error if closed again in FINALLY block.
}
catch (SqlException ex)
{
//error handling
}
finally
{
//close connection
oConn.Close();
}
|
|
#8
|
|||
|
|||
|
Quote:
ur design and logic. that is all ur design (screen design's corresponding code) will collected in test.aspx and the execution part will collected in test.aspx.vb so better write code in test.aspx.vb |
|
#9
|
||||
|
||||
|
12) Try and avoid throwing exceptions whenever possible if programming for a computer using a deep pipeline CPU (i.e. a P4). When an exception occurs, the CPU must save context and clear the entire pipe-line. There is also some overhead in the Common Language Runtime to deal with them I have noticed a visible stutter on a 2.4 ghz machine when a simple number parsing exception occurs in a .NET application
13) In ASP.NET, either avoid more advanced server controls (including panels) or update your servers browser tabs to allow non-IE browsers to correctly view your site. By default the XML file which tells the server which browsers can handle which commands (i.e. CSS, tables, frames etc) says that mozilla and company cannot handle CSS (hopefully will be fixed in 2.0) which is why the browser tabs must be updated |
|
#10
|
|||
|
|||
|
Give some tips of interoperability between Java and .Net. Actually we have to make the presentation layer in .Net. So , we have to convert the code of JSP in ASP.Net. So give me suggestion about how to do that. And without third-party tools. If possible plz give some examples code for that.....
Regard, Debdatta |
|
#11
|
||||
|
||||
|
TIP: StringBuilder vs String Concatenation
TIP: Never concatenate strings in a loop -- use a StringBuilder instead. There is a HUGE difference in resource usage in this one.
|
|
#12
|
||||
|
||||
|
If you are using Sql Server for your backend
Use Enterprise Library
__________________
c# coders are more sensitive (case sensitive, that is) 277.1826 Hz |
|
#13
|
|||
|
|||
|
14.) (or whatever number you're on) in C# use regions, (and VB or something else too if you can)
By putting 'region' and 'endregion' directives around your code you can collapse it in the .NET environment. This way if you have an overly complex piece of code you can summarize it and collapse it to one line, and only open it up if you need to. Code:
// some code
[-]#region Really Long Complex Math That Fixes the DataGrid
// lots of long lines
// obscure logic
// annoying syntax
#endregion
// some more code
upon hitting the [-] it will collapse to Code:
//some code
[+][Really Long Complex Math Taht Fixes the DataGrid]
//some more code
use these and you can better tell at a glance what your code does, and when debugging only open the pieces that you care about when something breaks. -MBirchmeier |
|
#14
|
||||
|
||||
|
In VB you can do regions like this
Code:
#Region "Variable Declaration..." Public mstrValue As String #End Region |
|
#15
|
|||
|