Breaking News

Editors Picks

Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Wednesday, April 3, 2013

Page has one or more controls that do not correspond with

Page has one or more <asp: Content> controls that do not correspond with
<asp: Content placeholder> controls in the Master Page RSS

Introduction:
Just now when i was created my master page it gives me this error. The page has one or more asp content that do not correspond with asp content place holder. What is wrong with my master page? Here is my code of master page
This error in the design view:
The page has one or more <asp: Content> controls that do not correspond with <asp: ContentPlaceHolder> controls in the Master Page.
Designer generated error in VS when we were viewing the login page in designer mode. The error was:
The page has one or more <asp: Content> controls that do not correspond with <asp: ContentPlaceHolder> controls in the Master Page.
I had a hunch that this might be the root cause of my nonfunctional login page. Now I was 100% sure that the contentplaceholderID in this login page was the same as defined in the Master Page. In order to find other reasons for this error, I did a Google search for this error message and fortunately reached link:

Solution:
It would appear that your page has <asp: content> tags which do not correspond to <asp: ContentPlaceHolder> controls in your Master Page.
For this type of solution, master pages never support comments in the format <! --    -->
This could be causing your error
Or
I changed from <title/> to <title><title/> and it also did the trick.
to fix this issue simply set <title></title> instead of <title /> in your master page.
Read more ...

“The Controls collection cannot be modified because the control contains code blocks”

Introduction
Here I will explain how to solve the problem “The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).” when running web application using asp.net. 
Description
I created one web application and added some of script files in header section of page like this
<head id="head2" runat="server">
<title>Light Page</title>
<link href="sunilstyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%= ResolveUrl("~/js/grid.js") %>"></script>
</head>

After add script file to header section i tried to run the application during that time I got error like “The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Server Error in 'ASP.Net' Application.


The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.


To solve this problem we have different methods
First Method
Remove JavaScript from the header section of page and add it to body of the page and run your application it will work for you.
Second Method
Replace the code block with <%# instead of <%=
<head id="head2" runat="server">
<title>Lightbox Page</title>
<link href="sunilstyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%# ResolveUrl("~/js/grid.js") %>"></script>
</head>

After replace code block with <%# instead of <%= add following code in page load

protected void Page_Load(object sender, EventArgs e)
{
Page.Header.DataBind();    
}

After add code run your application it will work for you

Read more ...

How to fix "Validation(): Element 'xxxx' is not supported

How to fix "Validation(): Element 'xxxx' is not supported" Visual Studio 2010
Introduction:
Since about a month ago,I started to get validation warnings at design time on asp.net server controls (any control actually) within the html design view for VS 2010,intellisense on all controls would not work at all,the messages look like this:

Validation(): Element 'Label' is not supported.
Validation(): Element 'GridView' is not supported
....etc

The compilation done successfully but the warnings still exist and intellisense is not working at the source tab

I tried to reset the settings of VS 2010 ,disabled all extensions and few other ideas but none of them solved the issue,I got stuck.

I did a search over the internet about this issue and found the Solution

Solution

Splendid,that article is a life savior,the idea is to remove the folder "ReflectedSchemas" from paths:
Remember also the "VisualStudio" part of the path will be different depending on the version installed.

Win XP : C:\Documents and Settings\{username}\Application Data\Microsoft\VisualStudio\9.0\ReflectedSchemas

Win 7: C:\Users\{username}\AppData\Roaming \Microsoft\VisualStudio\9.0\ReflectedSchemas


 
Note: make sure that "Show hidden files, folders, and drives" is selected from Folder Options ,also don't forget to close VS before deleting the folder.

This solution should work for VS2010 and VS2008,at VS2008 you have to delete ReflectedSchemas from folder 9.0 not 10.0.
Read more ...

How to create a new session in ASP.NET programmatically


If you want to create a new session (open a new window in a new session), without disturbing/loosing the other one, you will have to use the SessionIDManager.
Here is a short example (this will only work with <sessionState cookieless=”true” /> in the web.config):


protected void Page_Load(object sender, EventArgs e)
{
            if (!IsPostBack)
            {
                string ss1 = Session.SessionID;
                Session.Abandon();              
               Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));
            }
           
}
This code example clears the session state from the server and sets the session state cookie to null. The null value effectively clears the cookie from the browser.

When a user does not log off from the application and the session state time-out occurs, the application may still use the same session state cookie if the browser is not closed. This behavior causes the user to be directed to the logon page and the session state cookie of the user to be presented. To guarantee that a new session ID is used when you open the logon page (login.aspx), send a null cookie back to the client. To do this, add a cookie to the response collection. Then, send the response collection back to the client. The easiest way to send a null cookie is by using the Response.Redirect method. Because the cookies collection always has a value for the ASP.NET_SessionId, you cannot just test if this cookie exists because you will create a Response.Redirect loop. You can set a query string on the redirect to the logon page.

Or, as illustrated in the following code example, you can use a different cookie to tell if you are already redirected to the logon page. To help enhance security and to make sure that no one tries to open the logon page by using a second cookie together with the ASP.NET cookie, the following code example uses the FormsAuthentication class to encrypt and decrypt the cookie data.
Read more ...

Tuesday, October 9, 2012

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

While you are trying to read a CSV file and trying to get the data in a Dataset using Microsoft Text Driver in your 64 bit machine, you will be shown an error message as:

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Try the solution as I do. It worked for me:
1. Go to IIS and Application Pools in the left menu.
2. Click the project name in the listing.
3. Click the Set Application Pool Defaults.
4. In General Tab, make the Enable 32 Bit Application entry to "True"


Now it works.
Read more ...

Monday, August 6, 2012

Asp.Net Bind MSChart with Dataset and handle Click event of the chart


Introduction       
                  
        This tutorial uses the new MS Chart click event to render a column graph from a Data Table in C# and ASP.NET 2.0 to 4.0

Description
In this tutorial, we will be looking at the new addition to the .NET Framework, MS Charts click event. We will be rendering a bar chart from a Data Table and then click event of that bar chart, and show just how easy.
Before we begin anything, and even start up Visual Studio.NET, we first need to download and install the Chart extension. You can download from the above web address, and the install is a quick process - consisting of two axes. Once installed, we can start up Visual Studio and create a new Web Application. Then the first thing to do is add two references in the Web.config:
In system.web/http Handlers, add the following:
<httpHandlers>
      <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
    </httpHandlers>



Read more ...

Wednesday, August 1, 2012

Asp.Net Column Chart from DataTable in MSChart C#


Introduction                          
        This tutorial uses the new MS Chart to render a column graph from a Data Table in C# and ASP.NET 2.0 to 4.0
Description

In this tutorial, we will be looking at the new addition to the .NET Framework, MS Charts. We will be rendering a bar graph from a Data Table, and show just how easy Microsoft make it for us to do so. We can use the Chart control like other ASP.NET data controls, and assign it a data source.
Please note that MS Chart will not work in ASP.NET 2.0 and below. If you are working within 3.5 or 4.0, then you can download the MS Chart extension at the following
We will programmatically instantiate and populate a Data Table on page load. In a real-world application, the chart would be fed with data from an external source, like a database or XML file.
There is not just one way to render a Chart in ASP.NET. Using MS Chart, we can either give it a data source like any other data control or we can loop through the data values and plot each point on the graph individually. In this example, we will show you both ways.

Before we begin anything, and even start up Visual Studio.NET, we first need to download and install the Chart extension. You can download from the above web address, and the install is a quick process - consisting of two axes.Once installed, we can start up Visual Studio and create a new Web Application. Then the first thing to do is add two references in the Web.config:
In system.web/http Handlers, add the following:
For .net framework 3.0 and 3.5
<httpHandlers>
      <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
</httpHandlers>

For .net framework 4.0
<httpHandlers>
      <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
    </httpHandlers>

Read more ...

Grid layout with Background Image in WPF

Introduction                              

The grid is a layout panel with Background Image that arranges its child controls in a tabular structure of rows and columns. Its functionality is similar to the HTML table but more flexible. A cell can contain multiple controls; they can span over multiple cells and even overlap themselves.

Description

To add controls to the grid layout panel just put the declaration between the opening and closing tags of the Grid. Keep in mind that the row- and column definitions must precced any definition of child controls.
The grid layout panel provides the two attached properties Grid. Column and Grid. Row to define the location of the control.

Read more ...

Monday, July 30, 2012

how to create a simple File Watcher Windows Service Application


Introduction

This article will briefly explain how to create a simple "File Watcher” application to run as a Windows Service the coding language used is C#.


Description

Use FileSystemWatcher to watch for changes in a specified directory. You can watch for changes in files and subdirectories of the specified directory. You can create a component to watch files on a local computer, a network drive, or a remote computer.

Another very useful class, FileSystemWatcher, acts as a watchdog for file system changes and raises an event when a change occurs. You must specify a directory to be monitored. The class can monitor changes to subdirectories and files within the specified directory. If you have Windows 2000, you can even monitor a remote system for changes. (Only remote machines running Windows NT or Windows 2000 are supported at present.) The option to monitor files with specific extensions can be set using the Filter property of the FileSystemWatcher class
Read more ...

Friday, July 13, 2012

Get ASP.Net Grid View Row Value and its Row Index when clicked using JavaScript



Introduction

Get ASP.Net Grid View Row Value and its Row Index when clicked using JavaScript

Here I explained how to get the ASP.Net Grid View Row Value and its Row Index client side using JavaScript. He has also explained how we can find the Grid View Cells and the controls value inside the Grid View Template Fields client side using JavaScript.
Description

Below I have a simple ASP.Net Grid View. That content two columns SNo and Name both column are Template Fields.
When any gird View Cell is clicked, then Cell value and cell index value show on Alert box.


Read more ...

in ASP.NET copy cell value from one gridview and paste to another gridview


Introduction

Here I explained how to get and Set the ASP.Net Grid View Row value to other Grid View Row client side using JavaScript. This feature using Click on cell 2 value of grid view and then click on other grid view at any ROW then this value is copy the Second Grid View. And also this process also for second grid copy value from CELL 2 using click on cell then paste this value on first Gird view using click on first gird view.


Read more ...

Saturday, July 7, 2012

Sending email with attachment in ASP.NET


Introduction
In this article, I am describe how to send email with attachment in ASP.NET using System.IO, System.Net and System.Net.Mail namespaces in this article.
In ASP.NET, sending emails has become simpler. The classes required to send an email are contained in the System.Net.Mail. The steps required to send an email with attachment from ASP.NET are as follows: Below is sample code showing how to send email with attachment from ASP.Net using C#. With this code send main from Gmail SMTP server you can also configure your own SMTP server to change in web config file.
To configure SMTP configuration data for ASP.NET, you would add the following tags to your web.Config file.
Read more ...

Friday, July 6, 2012

How to Send Email from ASP .NET

Introduction
In ASP.NET, sending emails has become simpler. The classes required to send an email are contained in the System.Net.Mail. The steps required to send an email from ASP.NET are as follows: Below is sample code showing how to send email from ASP.Net using C#. With this code send main from Gmail SMTP server you can also configure your own SMTP server to change in web config file.
To configure SMTP configuration data for ASP.NET, you would add the following tags to your web.Config file.
<system.net>
  <mailSettings>
    <smtp from="YourEmailid@gmail.com" deliveryMethod="Network">
      <network host="smtp.gmail.com" port="587"   
               userName="YourEmailid@gmail.com"
               password="yourPassword"/>
    smtp>
  mailSettings>
system.net>    

Read more ...

Thursday, July 5, 2012

How to show gridview header when there is no data or empty in Asp.net


Introdcution

What happens if your grid view  control does not have any records to display? Well, if you set the EmptyDataText or EmptyDataTemplate properties, the grid will show something, only probably not what you'd like - the normal structure, as if it was populated with records. Here's a possible solution
Here I will explain how to display or show grid view header even if grid view does not contain data or show gridview header with no records.

Description

I got requirement like show the grid view header or header with message even if grid view does not contain any data. In our applications we have 3 example who show gird view

Read more ...

Tuesday, July 3, 2012

Create dynamic textbox using JavaScript in ASP.Net


Below is the aspx.Net page where we will build the dynamic textbox functionality using JavaScript. I have placed aspx button and Textbox to add the textboxes on DIV when click on button I am calling JavaScript function which I will explain later. Also I have html DIV control which will act as a container to hold the dynamic textboxes. Finally there’s an ASP.Net Button control which I used to show how to fetch the values of the dynamic textboxes generated using JavaScript server side and also retain the dynamic textboxes after Post Back.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DynamicControl.aspx.cs" Inherits="DynamicControl" %>

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>How to create dynamic textbox using asp.net and C#title>

    <script type="text/javascript" language="javascript">
    function CreateGridTable()
    {
    var txtSlot = document.getElementById("txtSlots");
    var div = document.getElementById("div1");
    var div2 = document.getElementById("div2");
    if(txtSlot.value != "")
    {
    var table = document.createElement('table');
    table.width="100%";
    table.className ='hovertable';
    div.appendChild(table);
    var tr1 = document.createElement('tr');
    table.appendChild(tr1);
    var td1 = document.createElement('td');
    td1.innerHTML = document.getElementById("Label1").innerHTML;
    tr1.appendChild(td1);
    for(var i = 1; i<= txtSlot.value; i++)
    {
    var tdH = document.createElement('td');
    tdH.innerHTML = String(i);
    tdH.width="50px";
    tr1.appendChild(tdH);
    }
    var tr2 = document.createElement('tr');
    table.appendChild(tr2);
    var td2 = document.createElement('td');
    td2.innerHTML = "Value";
    td2.width="50px";
    tr2.appendChild(td2);
    for(var i = 1; i<= txtSlot.value; i++)
    {
    var tdC = document.createElement('td');
    var txtC = document.createElement('input'); 
    txtC.type = "text";
    txtC.name = String("txt" + i);
    txtC.style['width'] = '45px';
    tdC.appendChild(txtC);
    tr2.appendChild(tdC);
    }
    }
   
    div2.style.display = "block";
    div.style.display = "block";
    return false;
    }
   
    script>

    <style type="text/css">
        table.hovertable
        {
            font-family: verdana,arial,sans-serif;
            font-size: 11px;
            color: #333333;
            border-width: 1px;
            border-color: #999999;
            border-collapse: collapse;
        }
        table.hovertable th
        {
            background-color: #c3dde0;
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #a9c6c9;
        }
        table.hovertable tr
        {
            background-color: #d4e3e5;
        }
        table.hovertable td
        {
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #a9c6c9;
        }
    style>
    <style type="text/css">
        .style1
        {
        }
        .style2
        {
            width: 100%;
        }
        .style3
        {
            width: 100%;
            height: 23px;
        }
    style>
head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="width: 48%; height: auto">
            <tr>
                <td class="style2">
                    <div id="divmain" runat="server" style="font-size: small; font-family: Arial;">
                        <table style="width: 100%; height: auto" class="hovertable">
                            <tr>
                                <td class="style1">
                                     
                                    <asp:Label ID="Label1" Text="Enter the No " runat="server">asp:Label>
                                     
                                    <asp:TextBox runat="server" ID="txtSlots">asp:TextBox>
                                td>
                            tr>
                            <tr>
                                <td class="style1" align="left">
                                    <br />
                                    <asp:Button ID="btnProcees" Text="Add Text Box" runat="server" />
                                td>
                            tr>
                        table>
                    div>
                td>
            tr>
            <tr>
                <td class="style3">
                    <div id="div1" style="display: none" runat="server" class="hovertable">
                    div>
                td>
            tr>
            <tr>
                <td class="style3">
                    <div id="div2" style="display: none" runat="server">
                        <br />
                        <asp:Button ID="BtnSave" runat="server" Text="Save" OnClick="BtnSave_Click" />
                         
                    div>
                td>
            tr>
        table>
    div>
    form>
body>
html>

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class DynamicControl : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            btnProcees.Attributes.Add("OnClick", "return CreateGridTable()");
        }
    }
    protected void BtnSave_Click(object sender, EventArgs e)
    {
        int slots = Convert.ToInt32(txtSlots.Text);
        for (int z = 1; z <= slots; z++)
        {
            string value = Convert.ToString(Request.Form["txt" + z]);
          
        }
    }
}

Description:

Dynamic Controls have to be recreated on Page PostBack and values entered in the
Text box, will be retained from viewstate. If we want to use Control ID to get value, we need to make sure that same control ID is used for recreating on postback. We can use a for loop to get text entered in the dynamic Text box

Downloads  
You can download the complete source code in  C# 



Read more ...

Contact Us

Name

Email *

Message *