.Net validation controls error: 'are you missing a using directive

  • Thread starter Thread starter Chris Halcrow
  • Start date Start date
C

Chris Halcrow

Hi there

I've successfully added some .NET validation controls to a page (using
<asp:RequiredFieldValidator ...), however when I try to set the 'display'
property to 'dynamic', my page then throws up the following error in the
browser:

CS1061: 'System.Web.UI.WebControls.TextBox' does not contain a definition
for 'Web' and no extension method 'Web' accepting a first argument of type
'System.Web.UI.WebControls.TextBox' could be found (are you missing a using
directive or an assembly reference?)

I had the same error when I tried to get a 'CompareValidator' to work, even
though I wasn't doing anything with the 'display' property (eventually gave
up and used a custom validator).

Code behind for the page specifies the following namespaces (I'm using C#):

using System
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

I'm using a master page, and the same namespaces are specified in the
code-behind for the master page

I've tried adding system.web as a reference to my project, still no luck.
Does anyone have a solution for this? Any replies gratefully received!

Thanks in advance, Chris :)
 
CS1061: 'System.Web.UI.WebControls.TextBox' does not contain a definition
for 'Web' and no extension method 'Web' accepting a first argument of type
'System.Web.UI.WebControls.TextBox' could be found (are you missing a
using
directive or an assembly reference?)

Seems like:

1) You're using ASP.Net 3.5
2) You're trying to set the property "Web" of "TextBox" either in
code-beside or in the aspx page.

Check if accidently there's Web='Something' in aspx page.

It's actually not really about namespaces it seems, but what controls you're
using and what code you've written.

--
Happy Hacking,
Gaurav Vaish
http://blogs.mastergaurav.com
http://eduzine.edujini-labs.com
---------------------------
 
Hi Gaurav

Thanks for the very quick reply. You're right that I'm using .NET 3.5.
Unfortunately, your suggestion is not the cause of the problem - I'm not
trying to set a property 'Web' equal to anything in code. The class in the
code behind is defined as:

public partial class RecordDetails : System.Web.UI.Page

I think that this means that the partial class inherits from
System.Web.UI.Page? Don't know if this gives any clues.

My code for the validators and the control they should validate is as follows:

<asp:TextBox ID="ReavailableFrom" runat="server"
CssClass="inputBox"></asp:TextBox>
<asp:RequiredFieldValidator
ID="ReavailableFromRequiredValidator" runat="server"
ErrorMessage="You must enter an estimate for 'Unavailable
To'" ControlToValidate="ReavailableFrom"
Style="margin-left: 15px"
EnableClientScript="False"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="ReavailableFromCompareValidator"
ControlToCompare="UnavailableFrom" runat="server"
ErrorMessage="CompareValidator" Operator="GreaterThan"
Type="Date"></asp:CompareValidator>

As I've mentioned, the RequiredFieldValidator on its own works, but as soon
as I add the code for the CompareValidator control, I get the error.

Any ideas? This has stumped at least two senior developers and me so far!

Thanks again, Chris
 
Hi Peter

Thanks for the advice. I don't know where the ASP.NET forum is, and Visual
C# .NET was the closest I could find. Do you have a link to a more
appropriate forum?

I'm confident that the missing "ControlToValidate" property is unrelated to
this issue

Thanks again, Chris

Peter Duniho said:
[...]
<asp:CompareValidator ID="ReavailableFromCompareValidator"
ControlToCompare="UnavailableFrom" runat="server"
ErrorMessage="CompareValidator" Operator="GreaterThan"
Type="Date"></asp:CompareValidator>

As I've mentioned, the RequiredFieldValidator on its own works, but as
soon
as I add the code for the CompareValidator control, I get the error.

Any ideas? This has stumped at least two senior developers and me so
far!

By the way, this may be nothing, but...

I note in the example on MSDN that the declaration for the
CompareValidator includes a "ControlToValidate" field, whereas yours does
not.

I don't know why that would cause the error you're seeing, and knowing so
little about ASP.NET I don't even know if that's a problem at all. But I
thought I'd mention it.

Pete
 
Thanks for the very quick reply. You're right that I'm using .NET 3.5.
Unfortunately, your suggestion is not the cause of the problem - I'm not
trying to set a property 'Web' equal to anything in code. The class in
the
code behind is defined as:

public partial class RecordDetails : System.Web.UI.Page

Can you please post across both the files - aspx and code-beside?

Or if it's too public a forum... mail at gaurav[~dot~]vaish[~at~]gmail.
 
Hi Guarav

I got rid of the offending code, to move onto something else, however I keep
getting a similar error every time I try to add any slightly unusual property
to a control, for example in the following page of aspx code, I've specified
RepeatDirection="Horizontal" as a property of the RadioButtonList, and I get
a very similar error ('System.Web.UI.WebControls.TextBox' does not contain a
definition for 'Web'). Before you ask, the error does say 'TextBox', but
identifies the RadioButtonList as the source of the problem. I've also
listed the code behind and the master page code and code behind:

-----EditSystem.aspx-----------

<%@ Page Language="C#" MasterPageFile="~/master/default.master"
AutoEventWireup="true"
CodeFile="EditSystem.aspx.cs" Inherits="Admin_AddSystem" Title="Untitled
Page" %>

<asp:Content ID="htmlTitle" ContentPlaceHolderID="htmlTitle" runat="Server">
IST Systems Status - Edit System
</asp:Content>
<asp:Content ID="head" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="dropDownMenus" ContentPlaceHolderID="dropDownMenus"
runat="Server">
<li><a href="/system_status/" title="Go to home page"
menu="home">Home</a></li>
<!--<li><a href="#" menu="menu2">Drop-down menu</a></li>-->
<li id="active"><a href="/system_status/Admin/ManageStatus.aspx"
title="Update system(s) including current status">
Update Systems</a></li>
<li id="help"><a href="/system_status/help.aspx" title="Help information"
menu="help">
Help</a></li>
</asp:Content>
<asp:Content ID="breadcrumb" ContentPlaceHolderID="breadcrumb" runat="Server">
<div class="breadcrumb">
<a href=''>IST</a> / <a href="/system_status/">
System Status</a> / Update Systems / <a
href="/system_status/Admin/ManageSystems.aspx">
Manage Systems</a> / Edit System
</div>
</asp:Content>
<asp:Content ID="main" ContentPlaceHolderID="main" runat="Server">
<form id="form1" runat="server" class="flow">
<br />
<div style="margin-left: 40px">
<h2>
Edit System</h2>
<br />
<br />
<fieldset class="float">
<br />
<table class="editSystemDetailsTable">
<tr>
<td class="editSystemDetailsTable">
System
</td>
<td class="editSystemDetailsTable">
<asp:TextBox ID="System" runat="server"
CssClass="inputBox"></asp:TextBox>
</td>
</tr>
<tr>
<td class="editSystemDetailsTable" CssClass="inputBox">
Category
</td>
<td class="editSystemDetailsTable">
<asp:DropDownList ID="lstCategories" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="editSystemDetailsTable" CssClass="inputBox">
Importance
</td>
<td class="editSystemDetailsTable">
(Lowest)
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
RepeatDirection="Horizontal">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:RadioButtonList>
(Highest)
</td>
</tr>
<tr>
<td class="editSystemDetailsTable">

</td>
<td class="editSystemDetailsTable">
<asp:Button ID="Save" runat="server" OnClick="Save_Click"
Text="Save" CssClass="marginLeft"
Style="text-align: center" />
</td>
</tr>
</table>
</fieldset>
<br />
<br />
<br />
<br />
</div>
</form>
</asp:Content>


--------------- EditSystem.aspx.cs ----------------

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 Admin_AddSystem : System.Web.UI.Page
{
private short srtSystemID;

protected void Page_Load(object sender, EventArgs e)
{

bool blnIsNewRecord = (Request.QueryString["id"] == null);

if (!blnIsNewRecord)
{ srtSystemID = Convert.ToInt16(Request.QueryString["id"]); }


#region initialisation of page
if (!Page.IsPostBack)
{
if (!blnIsNewRecord)
{
PopulateForm();

PopulateDropDowns();
}
}

#endregion

}

protected void PopulateForm()
{
using (DataSet dsSystemDetails =
DAL.SystemStatus.getSystemDetailsByID(srtSystemID))
{
//Category.Text =
dsSystemDetails.Tables[0].Rows[0]["ss_category"].ToString();
//System.Text =
dsSystemDetails.Tables[0].Rows[0]["ss_system"].ToString();
//UnavailableFrom.Text =
dsSystemDetails.Tables[0].Rows[0]["ss_down_from"].ToString();
}
}

protected void PopulateDropDowns()
{
using (DataSet dsCategories = DAL.SystemStatus.getCategories())
{
lstCategories.DataSource = dsCategories;
lstCategories.DataTextField = "ss_category";
lstCategories.DataValueField = "ss_category";
lstCategories.DataBind();
}
}


protected void Save_Click(object sender, EventArgs e)
{

// save details of new system

//strSystem = System.Text;


// save details to database, and redirect to 'Maintain System
Details' page
//DAL.SystemStatus.setSystemDetails(strSystem, strStatus,
datUnavailableFrom, datReavailableFrom, strReason, srtSystemID);

Response.Redirect("ManageSystems.aspx");
}
}

--------------- default.master ----------------

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="default.master.cs"
Inherits="master_default" %>

<!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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
<asp:ContentPlaceHolder ID="htmlTitle" runat="server">
</asp:ContentPlaceHolder>
</title>
<link rel="stylesheet" type="text/css" href="/core/template/sidebar.css" />
<link rel="stylesheet" type="text/css"
href="/core/template/default_css.asp" />
<link rel="stylesheet" type="text/css" href="/core/template/screen.css"
media="screen" />
<link rel="stylesheet" type="text/css" href="/core/template/print.css"
media="print" />
<link rel="stylesheet" type="text/css" href="/core/template/sidebar.css" />
<link rel="stylesheet" type="text/css" href="~/StyleSheet.css" />
<!--[if IE]>
<link rel="stylesheet" type="text/css"
href="/core/template/default.ie.css"/>
<![endif]-->
<link rel="shortcut icon" href="/core/template/images/logo.dev.ico" />

<script language="javascript" src="/core/punaAPI/punaAPI.js"
type="text/javascript"></script>

<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>

<script type="text/javascript">

// some code removed

</script>

<!-- whole page container-->
<div id="container_page">
<!-- main content wrapper (excludes footer) -->
<div id="container_content">
<div id='container_masthead'>
<!-- some code removed -->
</div>
<div id="navigation_bar">
<div id="navigation">
<ul id="nav">
<!-- add code similar to the following as the content of to the
dropDownMenus section, on each
individual page, and mark appropriate menu as being 'active' as
per the first <li> tag

<li id='active'><a href="/system_status/" title="Go to home
page" menu="home">Home</a></li>
<li><a href="#" menu="menu2">Drop-down menu</a></li>
<li id="menu3"><a href="/system_status/help.aspx" title="Help
information" menu="help">Help</a></li>

*uses script that follows this general format, as included in
this master page:*

<script type="text/javascript">
// some code removed
</script>
-->
<asp:ContentPlaceHolder ID="dropDownMenus" runat="server">
</asp:ContentPlaceHolder>
</ul>
</div>
</div>
<!-- if breadcrumbs make sense in the application... -->
<asp:ContentPlaceHolder ID="breadcrumb" runat="server">
</asp:ContentPlaceHolder>
<!-- main content -->
<div id="container_text">
<!-- if the page title is to be highly visible to the end user... -->
<h2 id='pageTitle'>
</h2>
<asp:ContentPlaceHolder ID="main" runat="server">
</asp:ContentPlaceHolder>
</div>
<!-- end main content -->
</div>
<!-- end main content wrapper -->
<!-- footer content -->
<!-- end footer content -->
</div>
<!-- end whole page container -->
</form>
</body>
</html>



--------------- default.master.cs ----------------

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.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

public partial class master_default : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{


}

}

----------------


Gaurav Vaish (a.k.a. MasterGaurav) said:
Thanks for the very quick reply. You're right that I'm using .NET 3.5.
Unfortunately, your suggestion is not the cause of the problem - I'm not
trying to set a property 'Web' equal to anything in code. The class in
the
code behind is defined as:

public partial class RecordDetails : System.Web.UI.Page

Can you please post across both the files - aspx and code-beside?

Or if it's too public a forum... mail at gaurav[~dot~]vaish[~at~]gmail.
 
Back
Top