Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x

ASP.NET

123K

Solutions

28K

Contributors

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

Share tech news, updates, or what's on your mind.

Sign up to Post

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
2
Industry Leaders: We Want Your Opinion!
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
0
DelegatesInC#
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that understanding with Experts-Exchange users.
2
 
LVL 11

Author Comment

by:ROMA CHAUHAN
Comment Utility
Hi St. Jimbo,

Thanks for your valuable inputs.

As this is my very first article so I was not aware of all these points. I have submitted my article with the specified modifications.  Please review it again.


Thanks,
Roma
0
Donut Hole Caching is the inverse of Donut cache. As the previous statement, the Donut Caching is used to cachea maximum portion of the view/page, but Donut Hole Caching is used to cache only small portion of the view/page.
0
Thought this will help someone who wants to learn Unity framework in ASP.NET MVC 4 and ASP.NET Web API. Since the controllers are called directly by the MVC framework and as soon as you start introduce Repository Pattern in your project , unity framework will be very handy create dependent objects in your MVC Controller or Web API Controller.  By Coding to Interfaces enables us to test the projects easily by any mocking frameworks.


Let us see how to use UNITY in MVC 4 Controllers.


There are 3 things should be followed while using Dependency Injection. Design, Register and Resolve.

1. Design

Simplest of 3 steps I guess. Have the controller constructor takes a repository Interface like this.

public class TeamsController : Controller
    {
        private readonly ITeamRepository teamRepository;


        public TeamsController(ITeamRepository teamRepository)
        {
	this.teamRepository = teamRepository;
        }
....
} 

Open in new window



2. Register

How we are going to register the above dependency injection so that when the controller is called the unity jumps in creates the dependent objects.

Registration can be done in two ways. Using the config.file and doing in the Code.

2.1 Let’s see how to register by web.config file.

2.1.1. Place below secion inside(configuration -> configSections)
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, …
1
Windows Identity Framework SDK Version 4.0. Fix for missing smart tag on FederatedPassiveSignIn ASP.Net user control.

If you have ever worked with the identity framework then I am sure you are aware of FedUtil, the utility used to configure a SecurityTokenService (STS) in the Relying Party application (RP).  

For me, I am relatively new to WIF, I have followed online tutorials and SDK samples to the T, nothing frustrates me more however than when a step in a tutorial does not work as intended.  I intend to use passive sign in for my application and therefore decided to utilize the FederatedPassiveSignIn control on my ASP.Net applications login page.

The instructions for doing so are quite clear; Drag and drop a FederatedPassiveSignIn control on to your web form, set the UseFederationPropertiesFromConfig control property to “True”.  From here you can either right click on the new control or expand the smart tag to reveal a URI that allows you to directly invoke FedUtil via the new control.

If you are like me and are using the Windows Identity Foundation SDK 4.0 you will notice that neither the smart tag nor the context menu option is available for invocation.

Per Microsoft documentation, the only time these two options would be unavailable is if the SDK itself is not installed (runtime only).  So I followed the steps found online via so many open blogs e.g. uninstall all WIF components and reinstall (annoyingly time consuming).  

Still no joy after uninstall …
0
 
LVL 2

Author Comment

by:DeekGeep
Comment Utility
Dear LHerrou, although my article does not meet minimum characters, it is still valuable information that should be made available and took significant research on my part to solve.  This information should be welcomed on experts exchange as it originated from me and has not been posted else where (yet).  If articles is not a good place for this information then please direct me to where a good place is.  If one does not exist then I will place this valuable fix in the public domain.
0
We can implement the Impersonation in an ASP.Net application based on the requirement for running an request under specific account else only the piece of business logic under specifc account (i.e Mainly used to access the network resources at runtime) other than the service account.
 
Implementation of the impersonation in an application can be achieved by configutaion at the application level (Web.Config , IIS) else code level (.CS , .VB etc files) implementation using the WindowsIdentity.Impersonate method to switch for specific account at runtime and return back to the account it’s switched to the process the request.

In general, ASP.Net application runs under “Network Service” account which is the configured in the Identity section of the application pool to which the virtual directory or web site configured.

Fig 1
Fig : 1

In the above picture it’s defined to run under “Network Service” and the same can be configured to use the different account and the pre-condition it needs is that the Account have to be under the “IIS_WPG” user group of the machine and “Network Servcie” is added to the group by default.

Fig 2
Fig : 2

ASP.NET does not use impersonation by default and code runs using the ASP.NET application's process identity. We can use the delegation to use impersonation token to access network resources and the ability to use delegation depends on your selected authentication mechanism and appropriate account …
0
 
LVL 15

Author Comment

by:santhimurthyd
Comment Utility
Sure Mark , Please procced.
0
Problem

Hi all,

   While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.

   If your ASP.NET page is heavy and will take some time to load, you risk that the user will close browser window or go to some faster web site.


Solution

Let we see how to  possible to reduce size of page without removing useful content.

1.       Change the Comment Line Client side to Server side in the aspx

<!--
      ‘****
     ‘code
--> 

Open in new window


 To
<%--
‘code
--%> 

Open in new window


2.  Remove any inline JavaScript , Create a external .js file and Call in the aspx

3   Explicitly Call Dispose or Close on Resources You Open

Try
  conn.Open()
…Finally
  If Not(conn Is Nothing) Then
    conn.Close()
  End If
End Try

Open in new window


4. Ensure Debug Is Set to False
<%@ Page [b]debug="false"[/b] ... %>

Open in new window


5   Remove any inline Style class, Create a external .CSS file and Call in the aspx

6   Set EnableViewState="false"  for label in the Aspx page
     [ If no need the viewstate value any control - set EnableViewState="false" ]

7 Disable the View State in server side for Datagrid Bound select columns

private void Page_PreRender(object sender, System.EventArgs e)
        {
            foreach (DataGridItem dgi in dgdItemList.Items)
            {
                dgi.Cells[ID].EnableViewState = false;
                dgi.Cells[ItemUD].EnableViewState = false;
                dgi.Cells[DateCreated].EnableViewState = false;
                dgi.Cells[Subject].EnableViewState = false;
            }
        }

Open in new window

5
 
LVL 29

Author Comment

by:Kumaraswamy R
Comment Utility
Reduce the Page size Asp.Net
0
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:

     
$("#<%=MyInputField.ClientID%>")

Open in new window


I suppose it just offends my sense of decency to put inline VBScript on an .aspx page.  So, I started looking at the jQuery selector core and found a nice little gem.  Now, it's not perfect, and there are certainly ways for it to fail, but in general I've found that if you feed the following the proper context, it always works:

Given an html element like this:

       
<asp:TextBox runat="server" id="MyInputField" />

Open in new window


Which gets rendered like this (since I use Master pages)

     
<input type="text" id="c100_Panel1_MyInputField" />

Open in new window


You can select the input field like this:

     
$("input[id$=MyInputField]");

Open in new window



The great part about this from my point of view is that my jQuery markup will match my .net markup.  This leads to the ability to loop through jQuery objects and do a bunch of things without needing to first determine the .net rendered client ID.  Also, I can use .net runat=server objects with jQuery and they will work together.  In other words, if I want to take some fields in an asp:Panel and paint them pretty or use JSON to complete them, I can do that with jQuery.  But if I want to then take the values of those fields and do server-side work with them when a button is clicked, the value of those …
2
 
LVL 60

Expert Comment

by:Kevin Cross
Comment Utility
skrile, I have read your "Pimp Exchange" article a number of times now and smile EVERY time I read the title by the way...I had not yet read this, though, for whatever reason. Very nice tip/trick. You have my Yes vote above!
0
 
LVL 16

Author Comment

by:Steve Krile
Comment Utility
Thank.  Just emerging myself in Knockoutjs now.  Mind is swelling.
0
Uploader

Introduction

This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks.

Background

I had to provide a way for users to upload a lot of pictures. The problem was that pictures were being taken with 12-16 mega pixel cameras at 4000x3000 resolution so the picture files were huge(>5MB). This made it prohibitive because it would take ages to upload even 50 pictures for server side processing hence I had to find a way of resizing the images on the client BEFORE upload to the server. In my search, I came across the open source plupload control which provides a brilliant upload functionality with progress update and client side resizing. The only problem was that all the samples were in PHP, so it took me some effort to get it working with ASP.NET. I am writing this article to help others who want to use this control in ASP.NET.


Using the Code

The control can be downloaded from http://www.plupload.com/index.php.

Once you unzip the contents to your project folder, you would need to provide two pages. One page needs to be an ASP.NET page while the other one can be either ASP.NET or simple HTML.

Here is the markup of the page that hosts the upload control:


 
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="UploadToCRM.aspx.vb" Inherits="ImageUploader.UploadToCRM" %>

<!DOCTYPE

Open in new window

0
 
LVL 1

Expert Comment

by:myaspnet
Comment Utility
thank you is work with me
0
 
LVL 83

Author Comment

by:CodeCruiser
Comment Utility
Glad it did.
0
On Demand Webinar: Networking for the Cloud Era
LVL 10
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Introduction

While developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET postback based on the control that caused the postback to occur. The action, for example, could be to set focus back to the control that caused the postback or to load remaining controls on the form based n the control that cause the postback.

In this article, we will look into the JavaScript __doPostBack function and then as a little walkthrough we will write one small program to determine the control that causes the postback


Let us take a look at the __doPostBack function shown below:
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}

Open in new window


The __doPostBack function takes two arguments eventTarget, and eventArgument. The eventTarget contains the ID of the control that causes the postback and the eventArgument contains any additional data associated with the control. One thng should be noted that the two hidden fields _EVENTTARGET and _EVENTARGUMENT are automatically declared. the value of the eventTarget and eventArgument are stored in the hidden fields. The two hidden variables can be accessed from code behind using the forms/params collection.

Finding the control that caused the PostBack:

0
 
LVL 2

Author Comment

by:kak_mca
Comment Utility
Subject: How can I edit the article to add some short explanation to the article?

Hi tedbilly,

I have clicked on EDIT ARTICLE to add some introduction for the purpose to provide a short explanation to the article, but I could not see any changes made when I clicked on SUBMIT ARTICLE button. How can I edit the article to add some introduction to the article?
0
 
LVL 2

Author Comment

by:kak_mca
Comment Utility
Hi mark_wills,
I think, I have done all the changes asked by reviewers / page editors.

Anything more changes required?

When can I expect the article to be published?

I feel that I don't have any more problems with the article.

Thanks and Regards,
Ashok kumar.
0
ASP.Net to Oracle Connectivity

Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client connecting to an Oracle database server.This article contain very basic and simple steps for the connectivity.

I came across this article : http://msdn.microsoft.com/en-us/library/ms971506.aspx which helped enourmously, and used quite a bit of it in achieving my own solution. The code and conetent below is a combination from the MS article and my own work in making it work.

It is assumed that developers know the concept of TNSNAMe.ora file on Oracle /admin/Netwrok folder where connetions for the database with IP and Port are declared. the same database connection need to use here.

Objective :

1. Connect to Oracle Database
2. Retrieve the data from database

1. Define connectionstring to Web.Config
<appSettings>
       <add key="conStr" value="Data Source=Name;User Id=UID; Password=Password"></add>
 </appSettings>

Open in new window


2. Import namespace for oracleconnections
Add a reference to System.Data.OracleClient.dll—the Microsoft .NET Framework Data Provider for Oracle—to your project
using System.Data.OracleClient;

Open in new window


3 .Define Oracle connection object

OracleConnection oraconn = null;

Open in new window


4.Code Behind Add function for connect to database
 
private bool ConnectDatabase()
	{
		oraconn = new OracleConnection(ConfigurationSettings.AppSettings["conStr"]);
		
		if (oraconn.State == System.Data.ConnectionState.Closed)
		{
			oraconn.Open();
		}
		return true;
	}

Open in new window


5. Function to call command from database
Create an OracleCommand object. Set its Connection property to the connection created . Set its  CommandType property to CommandType.Text

Open in new window

2
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
Comment Utility
Specifying username and password:
"Data Source=MyOracleDB;User Id=username;Password=passwd;Integrated
Security=no;"
This one works only with Oracle 8i release 3 or later

Declare the OracleConnection:

C#:
using System.Data.OracleClient;
OracleConnection oOracleConn = new OracleConnection();
oOracleConn.ConnectionString = "my connectionstring";
oOracleConn.Open();

VB.NET:
Imports System.Data.OracleClient
Dim oOracleConn As OracleConnection = New OracleConnection()
oOracleConn.ConnectionString = "my connectionstring"
oOracleConn.Open()
0
User art_snob encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.3.3) tends to ignore the no-cache HTTP headers, and decides at any rate to avoid page reload. This causes severe problems with ASP.NET, which relies on synchronization of code-behind (e.g. a.aspx.vb) with the Web page (a.aspx).

Here is a stripped-down example:
a.aspx
<%@ Page Language="VB" CodeFile="a.aspx.vb" Inherits="a" EnableViewStateMac="False" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns="http://www.w3.org/1999/xhtml">

<HEAD id="Head1" runat="server">
	<TITLE>a.aspx</TITLE>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</HEAD>

<BODY>
<FORM id="form1" runat="server">
	<div id="container">
		<asp:ScriptManager ID="ScriptManager1" runat="server">
		</asp:ScriptManager>  
		<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
			<ContentTemplate>
				<asp:Button ID="ServerButton" runat="server" OnClick="Button_Click" text="go to b.html on server" /><p />
				<asp:Button ID="ClientButton" runat="server" onClientClick="location = 'b.html'" text="go to b.html on client" /><p />
			</ContentTemplate>
		</asp:UpdatePanel>
	</div>
</FORM>
</BODY>
</HTML>

Open in new window

a.aspx.vb
Partial Class a
    Inherits Page

    Protected Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ServerButton.Click
        Response.Redirect("b.html", False)
    End Sub

End Class

Open in new window

Now, on any known browser, the ServerButton and the ClientButton produce the same result:
b.html
<html>
	<head>
		<title>b.html</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	</head>
	<body>
			<input name="goback" onclick="history.back()" type="button" value="go back" /></p>
			<input name="gotoA" onclick="location='a.aspx'" type="button" value="go to a.aspx" /></p>
			<input name="replaceA" onclick="location.replace('a.aspx')" type="button" value="replace to a.aspx" /></p>
			<input name="openA" onclick="window.open('a.aspx', 'top')" type="button" value="open a.aspx" /></p>
	</body>
</html>

Open in new window

And on all known browsers, all four buttons in b.html display a.aspx again and let you repeat the process. Except goback button and the Android browser.
If you start at a.aspx and then click goback, or the system Back button, you will be still able to use the  ClientButton, but the ServerButton will not work at all. Under the hood it will get an ASP.NET exception:
E/browser (xxx): Console: Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 0 http://xxx/ScriptResource.axd?d=31hrpqnrjCS7Ljksbfakhjr6vQHbaDyxah__zHgcOttSylOBq8Zbq2kxgVMdA3MThu4aquTF9WtwbL8sY19YcnLh9RlqCkMMQlaKeoC5pMVR-tgb3iU8M6inww0QtoQYLpIsOrH70stFuO0SE_LVrEyvT7miOJgBVPvhCD-3ekjwH95jk8pHDxgtqXOa4aGu0&t=2610f696:5

Open in new window

I have explained above what causes this problem. Now our task is to find an easy and reliable plumbing.
I will use an XMLHttpRequest to verify that the copy of the page is not coming from local cache, but is fresh from the server. This way, we can guarantee that code behind will be live.
Here is the Page_Load procedure in a.aspx.vb:

Open in new window

1
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource.

Example of web.sitemap file:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
     <siteMapNode  url="~/" title="Home"  description="Home">
         <siteMapNode url="" description="Menu 1" title="Menu 1">
             <siteMapNode url="" description="SubMenu 1" title="Sub Menu 1"/>
         </siteMapNode>
         <siteMapNode url="" description="Menu 2" title="Menu 2"/>
         <siteMapNode url="" description="Menu 3" title="Menu 3"/>
     </siteMapNode>
</siteMap>

Open in new window

Sample code to add to the page menu:
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu"
      EnableViewState="False" IncludeStyleBlock="False" Orientation="Horizontal"
      DataSourceID="SiteMapDataSource1">
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server"  ShowStartingNode="false" />

Open in new window

Running the application, we will have something like the next picture:
 menu1rc.png
To show or hide the menu depending on the type of access each user, we may define the Roles in each SiteMapNode.

Another way to control the menus visible, is to add an attribute in each SiteMapNode and depending on its value, or will not display each menu.

For this, the web.sitemap will be something like:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
     <siteMapNode  url="~/" title="Home"  description="Home" visible="true">
         <siteMapNode url="" description="Menu 1" title="Menu 1" visible="true">
             <siteMapNode url="" description="SubMenu 1" title="Sub Menu 1" visible="true"/>
         </siteMapNode>
         <siteMapNode url="" description="Menu 2" title="Menu 2" visible="true"/>
         <siteMapNode url="" description="Menu 3" title="Menu 3" visible="true"/>
     </siteMapNode>
</siteMap>

Open in new window

The attribute "visible" is that we will indicate whether or not the menu is shown, and we'll add the event MenuItemDataBound on Menu with the following code:
protected void NavigationMenu_MenuItemDataBound(object sender, MenuEventArgs e)
{     SiteMapNode node = e.Item.DataItem as SiteMapNode;
     if (!string.IsNullOrEmpty(node["visible"]))
     {
         bool isVisible;
         if (bool.TryParse(node["visible"], out isVisible))
         {
             if (!isVisible)
             {
                 if (e.Item.Parent != null)
                     e.Item.Parent.ChildItems.Remove(e.Item);
                 else
                     ((Menu)sender).Items.Remove(e.Item);
             }
         }
     }
}

Open in new window

Thus, we have our menu to show all nodes whose attribute value equals True.

To be able to directly control the menus that will be visible or not, I used a Treeview to bind the web.sitemap file and set all items to show a checkbox, which will indicate the status of the Visible attribute.

Open in new window

1
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via their mobile devices – and it is this which most developers/designers forget.

With mobile devices becoming mainstream, it is more important than ever that we as designers and developers convey the importance of optimized web sites to our clients. With this in mind, I would like to introduce some strategies I use when developing a website, or web application.

#1 Make sure no matter how many CSS stylesheets you use, they are placed in between your <head> tags.  This will make sure that your styling gets rendered by the browser in a timely manner relative to the rendering of the page.

#2 Wherever possible, combine your stylesheets into one.  This will decrease page load time by cutting down the parrellel downloads the browser has to make to request your page.  If you absolutely must have mutliple stylesheets, see below for a code snippet that will do this on the fly for you.  (written in VB.NET)

#3 We all love javascript, I personally am a big fan of jQuery, and the jQuery UI.  Make sure that no matter how many javascript includes you have, they are placed at the very bottom of the page right before the </body> tag.  This will make sure the page is rendered before any javascript can interupt the document.

#4 Wherever …
4
 
LVL 25

Author Comment

by:kevp75
Comment Utility
Great q from 'TheLearnedOne'

"I have one question about "App_Code".  That folder is usually only seen with "Web Site" model web sites, which don't have a project file.  I don't see any mention of this, which might confuse someone who has a "Web Application" model, which won't normally have that folder, unless it is created manually."

This project was initially built as a 'Web Site', and not a 'Web Application'.  Most of the projects I build, are 'Web Applications', and thus (as TheLearnedOne states) does not automagically pop in the 'App_Code' folder.

So, there are 2 solutions to this quandry.  One is to manually create the 'App_Code' folder, if you do not have one, and pop in the code as I state above...  or, if most are like me.  Put your class files in your Class Assembly.
0
 
LVL 25

Author Comment

by:kevp75
Comment Utility
I need to mention this as well.  This method will not work if you use 'Master Pages' in your site.  (I have not tried 'Themes' or 'Skins').

It appears Master Pages are rendered prior to the page content being rendered.  I do have an idea of how a work around may be accomplished, but I will save that for a later post (in this article), I just need to build and test it before I can say one way or another.
0
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x

The Web Site is a file/folder based Project structure.  It is designed such that pages are not compiled until they are requested ("on demand").  The advantages to the Web Site are:
      1) It is designed to accommodate non-.NET Applications
      2) Deployment is as simple as copying files to the target server
      3) Any portion of the Web Site can be updated without requiring recompilation of the entire Site.

The Web Application is a .dll-based Project structure.  ASP.NET pages and supporting files are compiled into assemblies that are then deployed to the target server.  Advantages of the Web Application are:
      1) Precompiled files do not expose code to an attacker
      2) Precompiled files run faster because they are binary data (the Microsoft Intermediate Language, or MSIL) executed by the CLR (Common Language Runtime)
      3) References, assemblies, and other project dependencies are built in to the compiled site and automatically managed.  They do not need to be manually deployed and/or registered in the Global Assembly Cache:  deployment does this for you

If you are planning on using automated build and deployment, such as the Team Foundation Server Team Build engine, you will need to have your code in the form of a Web Application.  If you …
3
 
LVL 4

Author Comment

by:PyanfarChanur
Comment Utility
Mark, thanks very much for your support!  I do this kind of stuff in-house all the time...as I realized I needed to do more with my ExpertsExchange account, it seemed natural to want to start publishing some of this stuff.

Thanks again - I look forward to adding the little bits and pieces of information I come across from time to time.
0
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful.

Problem:
After closing a pop-up window, the parent page should be refreshed automatically.

Solution:
In the parent page, call the method to pop-up a user defined page on any click event.
  var url = 'ManageFormsPopup.aspx';
 //Show the category window to manage categories
 var prefrence="height=400,width=500,status=yes,toolbar=no,menubar=no";
 window.open(url, null, prefrence);

Open in new window

In the child page, trigger the onbeforeunload method.
window.onbeforeunload = RefreshParentPage;
//  ... 
function RefreshParentPage()
{
   // Refresh the parent page.
   window.opener.location.href = window.opener.location.href;
}

Open in new window


Problem:
Inside an asp:panel control, RequiredFieldValidator is not working

Solution:
You can keep the RequiredFieldValidator outside of the panel.  This will not place the error message next to the text box. To place error message near to the text box, we have to validate explicitly using a Javascript function, like so:

function Validate()
{
  var categoryName = document.getElementById('<%=txtCategoryName.ClientID%>').value;

  if(categoryName.toString() == "")
  {
    document.getElementById('<%=lblValidate.ClientID%>').innerHTML = "Please enter Category Name";
    return false;
  }
  else {
    document.getElementById('<%=lblValidate.ClientID%>').innerHTML = "";
  }
  return true; 
}

Open in new window


Problem:
While displaying a PDF file in a page, Reponse.End() throws an exception.

Solution:
Instead of Response.End() we could use Response.Close() to avoid the exception.

if (System.IO.File.Exists(FilePathVal))
{
    FileInfo fi = new FileInfo(FilePathVal); 
    long size = fi.Length;
    Response.AddHeader("Content-Length", size.ToString());
    Response.ContentType = "application/pdf";
    Response.BinaryWrite(File.ReadAllBytes(FilePathVal));
    Response.Flush();
    Response.Clear();
}

Open in new window


Problem:
Before deleting a grid record, the user must be presented with a confirmation dialog.

Solution:
In the grid, use LinkButton template column.
<asp:TemplateColumn HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="lblDelete" CommandName="Delete" runat="server" Text="Delete"
 OnClientClick="javascript:return confirm('Are you sure you want to delete ?');"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>

Open in new window


Problem:
In a Grid link button (for example, clicking on Filename link button), a single click is not working sometimes.  Instead double clicking is working.

Solution:
The events should be bound to the link button while data bound itself using onItemDataBound event.
In client side:

Open in new window

4
 
LVL 16

Author Comment

by:Easwaran Paramasivam
Comment Utility
Happy Reading! Happy coding!!
0
 
LVL 1

Expert Comment

by:myaspnet
Comment Utility
thank you
0
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this was a daunting task since controlling the rendered dates with a link to the event seemed out of reach, well, once I sat down and started working, it was actually a simple task. There are a few examples of using a database to create event dates, but I never found one that created a pop-up of the events.  Lets quickly walk through it.

First, lets create a database of the necessary data.  I used Access in this example but can be easily migrated to your preferred database.  Create a table with the following columns and  data-types, (sample data included);

ID      eventDate      eventName      EventData      eventLink
2      10/21/2010      New Event      Testing a new event      http://www.mgfic.com

ID: AutoNumber
eventDate: Date/Number
eventName: Text
eventData: Memo
eventLink: Text

Once the database has been created and saved in the appropriate directory, (I'll use _database in this example), lets create a page with the Calendar Control embedded and the required CSS and JavaScript calls.

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html 

Open in new window

1
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need to specify the SkinSrc and ContainerSrc in the URL.  This little chunk of code provides just that checking the full hierarchy for overrides:

Protected Function GetSkinContainerSrc() As String

    Dim strReturn As String = String.Empty
    Dim objTabs As New TabController()
    Dim objTab As DotNetNuke.Entities.Tabs.TabInfo = objTabs.GetTab(Me.TabId)

    'Get the skin source
    'Check the tab settings first.
    Dim strSkin As String = objTab.SkinSrc

    If strSkin = String.Empty Then
        'Not in the tab settings, check the portal
        strSkin = PortalSettings.PortalSkin.SkinSrc
    End If

    'Cleanup the string if it doesn't have the global/local information.
    If strSkin <> String.Empty Then
        If strSkin.IndexOf("/Portals/") >= 0 Then
            If strSkin.IndexOf("/Portals/_default/") >= 0 Then
                strSkin = "[G]" & strSkin.Substring(strSkin.IndexOf("/Skins/") + 1)
            Else
                strSkin = "[L]" & strSkin.Substring(strSkin.IndexOf("/Skins/") + 1)
            End If
        End If

        strReturn += "&SkinSrc=" & Server.UrlEncode(strSkin.Replace(".ascx", String.Empty))
    End If

    'Get the container source
    'Check the module settings for the container first.
   

Open in new window

0
Free Tool: Port Scanner
LVL 10
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/call the modal popup from a hyper link control within the gridview control and finally some important javascript methods of the ASP.NET AJAX ModalPopupExtender control. So first let's see how to use the ModalPopupExtender control.

How to use the ASP.NET AJAX ModalPopupExtender control?

Drag and drop a ASP.NET button/LinkButton/ImageButton or any control to an aspx page. To add a ModalPopupExtender control, drag and drop the control from the toolbox or Select the control (button/LinkButton/ImageButton or any other control) and click the button with a greater than symbol as shown below.
image-thumb11.png
When you click the arrow you will get a menu with an “Add Extender” option as shown below.
image-thumb10.png
Click the “Add Extender” menu option and select “ModalPopupExtender” from “Extender Wizard” popup. Once you have added the ModalPopupExtender control you need an ASP.NET panel control. This is because the ModalPopupExtender control will show the content of the Panel control as a popup. Add ASP.NET Panel control and the content which you want to display as popup into the ASP.NET Panel control. Sample code with all the above requirement is pasted below. Don’t forget to drag and drop the ScriptManager control to the page.

Open in new window

4
 
LVL 9

Author Comment

by:Sandeep P R
Comment Utility
Yes I do agree. The simple thing they can do is expose a property in  MPE which will give the drop shadow javascript object. Once we have the object we can manipulate it according to our needs.
0
 

Expert Comment

by:nandiniraj
Comment Utility
Hi,

Im very new to this ajax controls. I just tried to get the popup. I had pasted your code as it is . It is not giving any error but if run on browser and click on the button, the popup (panel) is not being showed ;-(

Dont know where i went wrong. Should i write anything in code behind to make it work?
Please help me.


Thanks in Advance
Nandini
0
In this Article, I will provide a few tips in problem and solution manner.

Opening an ASPX page in Visual studio 2003 is very slow.


To make it fast, please do follow below steps:  

Open the Solution/Project.
Right click the ASPX file to be opened.

Select Open with…
Choose HTML Design Editor.
Click Set as Default option.
Restart the Visual studio.

Double clicking an ASPX page will now open faster.

Remembering connection string is difficult.


No need to remember the connection string. Follow below steps:

Open notepad. Save as “AnyName.udl”.
Open the created UDL file.
This will pop up Database selector window. Choose the database you would like to connect and give proper credentials.

Test the connection.
Once success, Open the UDL file with notepad the connection string will be there.

Don’t know the namespace for a particular class in Visual studio 2005.


You know the class name but not sure in which namespace it resides? (Say for Example NameValueCollection)

Type the classname in the .cs file (code behind for the ASP.NET page).
Right click the class name.
From the context menu select Resolve. The namespace will be added in the using namespace lists.

Your child ASPX page is not getting refreshed properly.

4
 
LVL 60

Expert Comment

by:Kevin Cross
Comment Utility
Nice collection of tips.  It is always good to have other tricks in the arsenal.  You have my Yes vote above.

For connection strings, I use this nice reference also: http://www.connectionstrings.com/

I love resolution of types.  It is good even when you know the namespace of the types you are using, but like to type out the names sometimes and then use this technique to automatically add the using clauses.  Occasionally, you will run into multiple choices where a class uses a common name that belongs to multiple namespaces, but typically as developers we should know which one we intended.  What I find as a nice backup is the Object Browser where I can see that a particular implementation has the methods/properties I intended to use.

Anyway, nice job!

Regards,
Kevin
0
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull content or data from www.bing.com.  I have found this particularly painful when doing SharePoint development.

One way to overcome this issue is by using a server-side proxy on the site running the JavaScript code. There is already are well documented PHP solutions on the web, however I couldn’t find very many .NET-based solutions. This simple C# code takes the URL passed to it through the URL encoded query string, retrieves the content of the URL using an HttpWebRequest and outputs in the original form it as if it were content on the site.

The following code can be added to an ASP.NET application or to SharePoint.  For SharePoint, you can place the two files (Proxy.aspx and Proxy.aspx.cs) into the "_layouts" folder (c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS).

Please Note: To keep this example simple and to the point it does not contain any error exception handling and such.  You can modify this code and add error handling as you see fit.  Also, allowing all websites to be proxied through your site could allow for malicious site content to appear as if they are coming from your site.  The Query String method below is not recommended for use on publicly accessible websites, instead …
5
 
LVL 60

Expert Comment

by:Kevin Cross
Comment Utility
Yes that is a function of the HTML5 XMLHttpRequests, so it is emerging technology that will present some more power in HTML code but also keep us on our toes with regard to security.

I mentioned this also in my Article Cross-Site Exploitations which is something to keep in mind when opening up this functionality.

By the way, you have my Yes vote above.

Kevin
0
 

Expert Comment

by:Bassam_Basamad
Comment Utility
You take look on the following links that explain easyXDM

http://www.codeproject.com/KB/scripting/easyXDM.aspx

Kind Regards,
0
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method.

So in this article I will demonstrate how to add and use the dropdownlist. Three basic steps, first is to add the dropdownlist, then we get the values for the list, and then the last step is to Set the value selected.


Step1 : Add a dropdownlist

1. open up your aspx page
2. Go to Toolbox and under the Standard Tab, you will find the DropDownList control
3. Double click on it (it will appear on the page)
4. move it to the location you desire on the page
5. click on the small right arrow of the dropdownlist and chose (Chose Data source)
6. follow up with the wizard and decide the value & Displayed Text of the dropdownlist


step2 : Get the value

To get the value its a very simple and straight forward, all you have to do is call the SelectedValue property. In this example I will add a button to the page just for the sake of the demo.

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim var1 As String
        var1 = DropDownList1.SelectedValue
    End Sub

Open in new window

     


Step3 : Set the value selected

Here comes the tricky part.

If you try the old (Logical) way of setting the value (like the code below), the basic approach would be, getting the value from a database and you keep it in a variable (var1) and now you want to set the selected value of a dropdownlist to var1.


Open in new window

0
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider class but don’t give you what other class they have used in the backend.  With this EE Article, I would not only show how to extend MembershipProvider class but will give you the full source code of the web service which is used instead of a database as a backend.

I have made use of the MembershipProvider many a times but I would like to share my experience in one of my project where I had to extend the MembershipProvider class to make use of an already existing web service of the client to validate user, create user, change password etc.   I will show how to extend MembershipProvider class and write your custom MembershipProvider class.

Since I cannot reveal what webserivce was used in the website developed for the client, I will create my own webservice to mimic the exact behavior as in the website. So let's start by creating a webservice which will have methods to create a user, validate user credentials and finally change the user’s password. Once the webservice is done, we will extend the membership class.  Below is the code for the webservice.

WebService program code
[WebService(Namespace = "http://tempuri.org/")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
public class 

Open in new window

3
 
LVL 8

Expert Comment

by:PagodNaUtak
Comment Utility
Thank you, very much for this tutorial, as a begginner in web development this article really help me alot.

Nice work!
0
 
LVL 9

Author Comment

by:Sandeep P R
Comment Utility
Thanks. I am happy that it helped you a lot.
0
In this article we will see how to show and hide a ASP.NET AJAX’ (AJAXControlToolkit) ValidatorCalloutExtender control using Javascript.  Below is an .aspx page with a validator callout control.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="AJAXControls" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title>Untitled Page</title> 
</head>

<body> 
    <form id="form1" runat="server"> 
    <div> 
        <!--ASP.NET Drop down control--> 
        <asp:DropDownList ID="status" runat="server" > 
            <asp:ListItem Selected="True" Text="Select" Value="0" />
            <asp:ListItem Text="One" /> 
            <asp:ListItem Text="Two" /> 
            <asp:ListItem Text="Three" /> 
        </asp:DropDownList> 
        <!--ASP.NET Required Field Validator to validate the drop down.--> 
        <asp:RequiredFieldValidator ID="statusValidator" runat="server" ErrorMessage="Please choose a value other than 'Select'" 
            ControlToValidate="status" InitialValue="0" Visible="true">
        </asp:RequiredFieldValidator> 
    <!--Validator callout control--> 
        <AJAXControls:ValidatorCalloutExtender ID="statusValidator_ValidatorCalloutExtender" 
            runat="server" 

Open in new window

4
 
LVL 9

Author Comment

by:Sandeep P R
Comment Utility
Hi Bob,

The grammatical corrections look great. I don't have anything to add to the article.

Regards,

Sandeep
0

ASP.NET

123K

Solutions

28K

Contributors

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications