Category Archives: ASP.Net

Code Snippets ASP.Net ASP.Net 2.0

Add value for dropdown list in asp.net


ListItem li =new ListItem();
 li.value="PT";
 li.Text="Portugal";
 dropdownlist1.Items.Add(li);

or


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;
}
}
&lt;/script&gt;
.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

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.

ValidateRequest=&quot;false&quot;

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

asp.net 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;&lt;script&gt;&quot;)
sb.Append(&quot;window.open('http://www.galhano.com', '', '');&quot;)
sb.Append(&quot;&lt;/script&gt;&quot;)

Dim cstype As Type = Me.GetType()

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

End Sub

AJAX ASP.Net

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;ContentTemplate&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;ProgressTemplate&gt;
&lt;asp:Image ID=&quot;imgAjaxLoader&quot; runat=&quot;server&quot; ImageUrl=&quot;~/Icon/ajax-loader.gif&quot;/&gt; 
&lt;/ProgressTemplate&gt;
&lt;/asp:UpdateProgress&gt;

&lt;/ContentTemplate&gt;

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

&lt;/asp:UpdatePanel&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.

 

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.selectednodechanged.aspx

http://forums.asp.net/t/1361178.aspx/1

.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!

http://en.googlemaps.subgurim.net

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.

source: http://forums.asp.net/p/338021/355306.aspx#355306

.NET ASP.Net Microsoft

List of Request.ServerVariables

ALL_HTTP HTTP_CONNECTION:Keep-Alive HTTP_ACCEPT:*/* HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_ACCEPT_LANGUAGE:sv HTTP_HOST:localhost:1229 HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)
ALL_RAW Connection: Keep-Alive Accept: */* Accept-Encoding: gzip, deflate Accept-Language: sv Host: localhost:1229 User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)
APPL_MD_PATH
APPL_PHYSICAL_PATH D:\code\web\demos\membership\
AUTH_TYPE NTLM
AUTH_USER SYSTEMEN-D9AE02\Stefan Holmberg
AUTH_PASSWORD
LOGON_USER SYSTEMEN-D9AE02\Stefan Holmberg
REMOTE_USER SYSTEMEN-D9AE02\Stefan Holmberg
CERT_COOKIE
CERT_FLAGS
CERT_ISSUER
CERT_KEYSIZE
CERT_SECRETKEYSIZE
CERT_SERIALNUMBER
CERT_SERVER_ISSUER
CERT_SERVER_SUBJECT
CERT_SUBJECT
CONTENT_LENGTH 0
CONTENT_TYPE
GATEWAY_INTERFACE
HTTPS
HTTPS_KEYSIZE
HTTPS_SECRETKEYSIZE
HTTPS_SERVER_ISSUER
HTTPS_SERVER_SUBJECT
INSTANCE_ID
INSTANCE_META_PATH
LOCAL_ADDR 127.0.0.1
PATH_INFO /membership/servervariables.aspx
PATH_TRANSLATED D:\code\web\demos\membership\servervariables.aspx
QUERY_STRING
REMOTE_ADDR 127.0.0.1
REMOTE_HOST 127.0.0.1
REMOTE_PORT
REQUEST_METHOD GET
SCRIPT_NAME /membership/servervariables.aspx
SERVER_NAME localhost
SERVER_PORT 1229
SERVER_PORT_SECURE 0
SERVER_PROTOCOL HTTP/1.1
SERVER_SOFTWARE
URL /membership/servervariables.aspx
HTTP_CONNECTION Keep-Alive
HTTP_ACCEPT */*
HTTP_ACCEPT_ENCODING gzip, deflate
HTTP_ACCEPT_LANGUAGE sv
HTTP_HOST localhost:1229
HTTP_USER_AGENT Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)