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


Some ASP.NET Practical tips

Published on
10,939 Points
4 Endorsements
Last Modified:
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.

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

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

Inside an asp:panel control, RequiredFieldValidator is not working

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

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

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";

Open in new window

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

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

Open in new window

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

The events should be bound to the link button while data bound itself using onItemDataBound event.
In client side:
<asp:DataGrid ID="grdResources" runat="server" AutoGenerateColumns="False"
 Width="100%" DataKeyField="ResID" OnItemDataBound="grdResources_ItemDataBound">

Open in new window

In server side:
protected void grdResources_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
Private const URL = "some file name";
   if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==  ListItemType.AlternatingItem)
    lnkSelect.Attributes.Add("onclick", "javascript:window.open('" + URL + "'); return true;");

Open in new window

From a string array, you would like to check existence of a string quickly?
Create a List item for the string array and use Contains method of it.

private const string FormsAdmin = "FormsAdmin";
string[] Roles = cUser.Roles; 
List<string> RoleList = new List<string>(Roles);
if (RoleList.Contains(FormsAdmin))
  // Found the string.


Open in new window

Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 16

Author Comment

by:Easwaran Paramasivam
Happy Reading! Happy coding!!

Expert Comment

thank you

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Join & Write a Comment

In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Other articles by this author
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month