Category Archives: ASP.Net

Code Snippets ASP.Net

Measure a function’s performance

Imports System.Diagnostics

Dim sw As New Stopwatch()
' Do the work here
Console.WriteLine("Elapsed time: {0}", sw.Elapsed.TotalMilliseconds)

Code Snippets ASP.Net ASP.Net 2.0

Add value for dropdown list in

ListItem li =new ListItem();


dropCategory.Items.Add( New ListItem( "Portugal", "PT" ) )

Code Snippets .NET ASP.Net

Set Calendar Extender’s SelectedDate=”<%=DateTime%>”

&lt;asp:TextBox ID=&quot;txtDate&quot; runat=&quot;server&quot; &gt;&lt;/asp:TextBox&gt;
&lt;cc1:CalendarExtender ID=&quot;CalendarExtender1&quot; runat=&quot;server&quot; TargetControlID=&quot;txtDate&quot; Format=&quot;MM/dd/yyyy&quot; OnClientShowing=&quot;showDate&quot; &gt; &lt;/cc1:CalendarExtender&gt;
&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt;
function showDate(sender,args)
if(sender._textbox.get_element().value == &quot;&quot;)
var todayDate = new Date();
sender._selectedDate = todayDate;
.NET ASP.Net Microsoft

Enterprise Library

The Microsoft Enterprise Library is a collection of reusable software components (application blocks) designed to assist software developers with common enterprise development cross-cutting concerns (such as logging, validation, data access, exception handling, and many others). Application blocks are a type of guidance; they are provided as source code, test cases, and documentation that can be used “as is,” extended, or modified by developers to use on complex, enterprise-level line-of-business development projects.

read more »


ASP.NET 4.0 potentially dangerous Request.Form value was detected

This was because .NET detected something in the entered text which looked like an HTML statement.
This is a feature put in place to protect your application cross site scripting attack and followed accordingly.

To disable request validation, I added the following to the existing “page” directive in that .aspx file.


For .NET 4, we need to add requestValidationMode=”2.0″ to the httpRuntime configuration section of the web.config file like the following:

&lt;httpRuntime requestValidationMode=&quot;2.0&quot;/&gt;

But if there is no httpRuntime section in the web.config file, then this goes inside the <system.web> section.

If anyone wants to turn off request validation for globally user, the following line in the web.config file within <system.web> section:

&lt;pages validateRequest=&quot;false&quot; /&gt; 
ASP.Net Microsoft button: Open a popup window after a button click

&lt;asp:button runat=&quot;server&quot; ID=&quot;button1&quot;  Text=&quot;popup&quot;  &gt;&lt;/asp:Button&gt;

vb sample:

Protected Sub button1_Click(sender As Object, e As System.EventArgs) Handles button1.Click

Dim sb As New StringBuilder()
sb.Append(&quot;'', '', '');&quot;)

Dim cstype As Type = Me.GetType()

Page.ClientScript.RegisterStartupScript(cstype,&quot;test&quot;, sb.ToString())

End Sub


Triggers in updatepanel (sample)

This sample shows how to trigger a updatepanel from a control outside of it:

&lt;asp:UpdatePanel ID=&quot;uPanel1&quot; runat=&quot;server&quot; UpdateMode=Conditional &gt;

&lt;asp:TextBox ID=&quot;txtMyNumber&quot; runat=&quot;server&quot;&gt;&lt;/asp:TextBox&gt;

&lt;asp:UpdateProgress ID=&quot;UpdateProgress1&quot; runat=&quot;server&quot; AssociatedUpdatePanelID=uPanel1&gt;
&lt;asp:Image ID=&quot;imgAjaxLoader&quot; runat=&quot;server&quot; ImageUrl=&quot;~/Icon/ajax-loader.gif&quot;/&gt; 


&lt;asp:AsyncPostBackTrigger ControlID =&quot;btnUpdateMyNumber&quot; /&gt;


&lt;asp:Button  runat=&quot;server&quot; ID=&quot;btnUpdateMyNumber&quot; Text=&quot;Set My Number&quot;  /&gt;

ASP.Net Microsoft

TreeView.SelectedNodeChanged Event, doesn’t fire

Occurs when a node is selected in the TreeView control.

If we assign any URLs to the NavigateUrl propery of the TreeNode, it will render as a <a> tag, it will not do postback, so it will not file the event;

If we do not assign any URLs to the NavigateUrl propery of the TreeNode, it will render as a short JavaScript which used to postback.

So I think maybe you have assign URLs to the NavigateUrl propery of the TreeNode.

.NET ASP.Net Google

ASP.NET GoogleMaps User Control

GoogleMaps.Subgurim.NET is the most advanced Google Maps control for ASP.NET 2.0.
Making available the full power of the official GoogleMaps API, yet without the need of a single line of javascript code: you code only in ASP.NET!
To get going, you just drag the control from the toolbox onto the Visual Studio design surface, and with a few lines of code you will be able program powerful Google Maps applications!

ASP.Net Tips & tricks

vbc : warning BC40010

error message:
I get this message when building my Assembly :


Updating references…
Performing main compilation…
vbc : warning BC40010: Possible problem detected while building assembly ‘asdasd’: Referenced assembly ‘asdasd’ is a localized satellite assembly
Building satellite assemblies…

—- Done —

Rebuild All: 2 succeeded, 0 failed, 0 skipped


The assembly you are building is localized differently than the assembly that are referencing.

This probably means that somewhere in the source code for “asdasd” you have an AssemblyCultureAttribute that is present. Code assemblies should never have this attribute — if you remove it, the problem should go away.