.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

ASPX Literal vs Code

Posted By:      Posted Date: October 25, 2010    Points: 0   Category :ASP.Net

I've many literals in aspx page, Im just wondering is there any performance issue if I use many of them.

Like these

<input type="text" id="gen_name_tb" style="width: 100%" value='<%=(fileFile != null ? fileFile.Name : "") %>' /> 

<input type="text" id="gen_subtitle_tb" style="width: 100%" value='<%=(fileFile != null ? fileFile.Subtitle : "") %>' />

View Complete Post

More Related Resource Links

Code works on aspx but not ascx


Not sure which category to put this question in, so I will put it in here.

Just to give you an idea of the layout of my solution, I have the main project, along with 2 class libraries, BLL and DAL.  (Business Logic Layer and Data Access Layer)

The BLL refers to the DAL and the main project refers to the BLL.

I had a test website and the code worked fine, but the same code will not work on the real project. The only difference is that in the test project, the code was on an aspx code behind, whereas in the real project, it is an ascx code behind (Web User Control )

The code is:

Dim connectionString As String = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ConnectionString
        Dim recordEntry As New UserRecord(connectionString)
        recordEntry.UserName = "TestName"
        recordEntry.BMI = bMI
        recordEntry.BMR = bMR
        recordEntry.FTM = fTM
        recordEntry.TDEE = tDEE
        recordEntry.TodayDate = dateForToday

Dim connectionString As String = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ConnectionString

close aspx page after executing code behind


I am working in vs 2008, C#.

Load event in my aspx page is having a set of database operations .So after completing those operations i want to close the aspx page.

for that i am calling 

window.close() methond onload event of the body. Its closing the aspx page but it is showing the confirmation message before closing the page.

I dont want to show that message box.

How can i claose an aspx page without showing any message?.

Pls help me



Create new aspx-page from code


Hello everyone.

I'm am looking for a general idea about the following:


My customer is looking for an application - a sort of webshop-like thingie, where each product has its own infopage with a unique URL.

He does NOT want an actual CMS.

I could - and probably will - use querystrings, like http://www.example.com/products.aspx?pID=21, and then get the content from the database, but is it possible - or rather possible without too much bother - to let the administrator input text via a webform, and then form code create a contentpage like http://www.example.com/product21.aspx

Have a nice weekend



[Sharepoint 2007]Parse error when I add code behind the page to a normal aspx page ?


Hi all,

I dont need this form to be embedded into Sharepoint. I am adding this webpage into Sharepoint because i has issues due to cross-domain permission. I cannot call refresh sharepoint from my op up window  webpage. Therefore i want to add my webpage into the same domain as sharepoint.

I have added the webpage aspx form into Sharepoint from the sharepoint designer 2007. I would like to add code behind the page too.

What i have done at the moment was to create a project in visual studio for the code behind the page. I folloed this article :



Then i have added the dll intothe bin of my sharepoint site. i have also added in webconfig the dll.

However i got the following error :

Parser Error Message: The codefile attribute on the page directive is not allowed in this page.

Source Error: 

Line 1: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="FormOragniseMeeting.aspx.cs" Inherits="FormOrganiseMeeting.FormOrganiseMeetingCodeBehind" %>
Line 2: 
Line 3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">





Setup file(*.msi) also includes .aspx.cs (source code) files also


My project is recently migrated from 2008 to 2010

actualy we developed project in VS 2005 in that we created setup file but when we migrated to vs2008 setup file giving problem to us.

now when we make setup file it is including .aspx.cs files also but this if we publish our project it wont including source code.

why setup file including .aspx.cs files is there any way to change.

plz replay ASAP

where i should put jscript code in aspx page, which created by inheriting a master page


hi budies,

 i am creating a simple web portal, but i am stuck in a aspx page which created by inheriting master page ,

there is some jscript code, but i don't know where to put this code in that page.

please help out ppls. 

thanx in advance 

How can i return a value from a simple WebForm.aspx to javascript code.


Hi Experts.

How can solve this problem; Suppose you write a simple JavaScript code in form tag like this:

<script  language="javascript">

                Var type="100";

                Var result = ';

Var iframe = '<iframe src="WebForm1.aspx?"t=' + type + '"></iframe>';

Document.write(iframe);           // call WebForm1.aspx in iframe tag

Document.write(result);            //write the result that return from WebForm1.aspx


I want return the value from WebForm1.aspx and save it in result variable. How can I do?How can i return a value from WebForm1.aspx and save it in result variable?

With Regards.Mojtaba

Code in an .aspx file that has literally been commented out is being compiled anyway...Why?


A bug kept occuring in my website that was telling me a certain field/column didn't exist. It took me about 2 hours to track this bug down because it was occuring in a part of the .aspx file that I would have never even thought to look. It was occuring because of a control(ListView I believe) that had been "completely" commented out using the <!-- --> tags. The text was all green which gave me the re-assuring feeling that this code would not be included in the website. I finally decided to search my entire .aspx page for any occurences of the variable it kept insisting couldn't be "databound" and sure enough it was inside a template of a ListView control that was commented out. I changed the name of the field it kept telling me didn't exists and the bug disappeared. Im writing this question from memory so my details are somewhat sketchy but I do know one thing. It took me 2 hours to track down a bug because code that had been commented out was being compiled inside an .aspx file. So my basic question is why does this happen? Im sure this can't be a bug otherwise Microsoft would have already discovered it. Is there a configuration option I can set in Visual Studio? I couldn't find it.

FormsAuthentication.SetAuthCookie FROM a aspx.cs code behind file?


Big picture: I want most people to have to login, via the forced login.aspx page.  But, if they use the following link and id (a subdirectory default.aspx file).. then I want to automatically authenticate them (there is actually a database of ids on sql server in the background) .. and then I want to send them to the page that they should 'now' be able to access (as it requires an authenticated user..

My problem is that FormsAuthentication.SetAuthcookie(userName, false); does not seem to work or be supported in this location.



default.aspx.cs   (in /a subdirectory)

public partial class a_Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        string userName = knownDBusername;

        //correct username returned for that id, so we logged in that username
        FormsAuthentication.SetAuthCookie(userName, false);



Sharepoint 2010 error on username in ASPX code


Here is the error:

Web page error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.6; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E)
Timestamp: Tue, 2 Nov 2010 20:12:57 UTC

Message: Expected '}'
Line: 1076
Char: 440
Code: 0
URI: http://my.local.sharepoint2010server/Lists/TreatmentRoomB/calendar.aspx

I have reset the users profiles and even had the user use a different computer. here is what I think the deal is. Her last name is "O'Tool", and when the list is generating the calendar view it is freaking out... could it be the "'" in her name?

I have tried to go to the back end database and remove her, or at lease change the name.. but can't find the information.

the page works great for anyone else, even on the same computer?  



asp.net front end (.aspx) translated into html code


Hi All,

Could some please shed me a light on how does the asp.net front end, which as asp server controls as well as html been translated into hmtl by asp.net web server during run time.

This is .aspx file:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<table style="text-align:center;">
        <td>Welcome to <strong>Moon Page</strong></td>

This is the html code generated by asp.net web server

<!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" >
	Untitled Page
</title><link href="../Stylesheet1.css" rel=&quo

Binding an ObjectDataSource to a property in aspx code, not code-behind


This should be simple to do, but I haven't been able to find a solution.

I want to bind an ObjectDataSource to a property in my asp page and I want to do it in the page's aspx code, not in code-behind. I've already done it in code-behind, as follows:

protected void Page_InitComplete(object sender, EventArgs e)
   odsBooks.DataSource = SelectedBook;

I'd prefer to get rid of the ugly code-behind and just do this in mark-up. Something like

<asp:ObjectDataSource ID="odsBooks" runat="server"

This gives me a run-time error: Cannot create an object of type 'System.Object' from its string representation 'SelectedBook' for the 'DataSource' property.

Is there a way of doing this declaratively and not in code-behind?

Further, what if what I want is to actually use a child property of the property in question? For example, if my Book object has a ReaderComments collection, can I databind to it decaratively in the aspx mark-up?

export datatable from .net code page (aspx.cs) to sql stored procedure


Hi experts

Can any body tell can we pass datatable from code page to sql stored procedure. If yes tell me how.


Any sugession acceptable.



Problem with Web Handler - Code works as .aspx, but not .ashx


I'm trying to cover a page that is code-only to a web handler. However, I'm having problems figuring out why the code works when used in the code-behind for the .aspx file but not the .ashx page.

.ASPX Page Code Behind


Partial Class launchsite
    Inherits System.Web.UI.Page

    Protected Sub Page_Load() Handles Me.Load

        If Len(Session("UserDashboardURL")) > 0 Then
            If Len(Session("UserCurrentShowNumber")) = 0 Then
                Response.Redirect("~/development/content/dashboards/" + Session("UserDashboardURL"))
                If InStr(Session("UserDashboardURL"), "?") = 0 Then
                    Response.Redirect("~/development/content/dashboards/" + Session("UserDashboardURL") & "?ShowNumber=" & Session("UserCurrentShowNumber"))
                    Response.Redirect("~/development/content/dashboards/" + Session("UserDashboardURL"))
                End If
            End If
        End If

    End Sub

End Class



<%@ WebHandler Language="VB" Class="Handler" %>

Imports System
Imports System.Web
Imports System.Web.HttpContext
Public Class Handler : Implements IHttpHandler
    Public Sub ProcessR

need aspx.cs code for purchase module

<%@ Page Language="C#" MasterPageFile="~/main.master" AutoEventWireup="true" CodeFile="Salesdetails.aspx.cs"
    Inherits="Salesdetails" Title="Sales Details" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script type="text/javascript" language="javascript">
      function Validate_SalesMaster()
            var msg = "";
            var str = "";
            var ch = "";
            var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
            var regex = /^[\w]*$/;

Code Optimized Web Development Profile (VS 2010 and .NET 4.0 Series)

When you first run VS 2010 it prompts you to select an IDE profile to use. The profile you select will configure how tool windows are displayed/docked in the IDE by default and set the default keyboard shortcuts. You can then customize any of these settings by using the Tools->Options menu within the IDE and then override/change them. You can also later reset your profile and pick a different one by choosing the Tools->Import and Export Settings menu command.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend