By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,289 Members | 3,049 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,289 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 :)
Jul 22 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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
---------------------------
Jul 23 '08 #2

P: n/a
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

"Gaurav Vaish (a.k.a. MasterGaurav)" wrote:
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
---------------------------
Jul 24 '08 #3

P: n/a
On Thu, 24 Jul 2008 16:26:01 -0700, Chris Halcrow
<Ch**********@discussions.microsoft.comwrote:
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.
You may not be doing so explicitly. But you must be doing so _somehow_,
otherwise the compiler wouldn't generate that error message.
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.
I don't see how it would.

Nothing you've posted so far includes a reference to a "Web" method
anywhere. But the error message makes it pretty clear that some code is
trying to reference a "Web" method on the TextBox class.

The fact is, the C# newsgroup is a pretty poor place to look for answers
to questions like this anyway. Your issues seems strongly related to your
use of ASP, and I'm pretty sure there's an ASP.NET newsgroup where your
question would likely be much more familiar to those reading it.

But if you really want to get help in this newsgroup, you'll need to post
a concise-but-complete code sample that reliably demonstrates the problem,
so that the people reading your post can figure out how the reference to
"Web" is getting made. I don't think there's any way to answer the
question without that sort of information.

Pete
Jul 24 '08 #4

P: n/a
On Thu, 24 Jul 2008 16:26:01 -0700, Chris Halcrow
<Ch**********@discussions.microsoft.comwrote:
[...]
<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
Jul 24 '08 #5

P: n/a
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" wrote:
On Thu, 24 Jul 2008 16:26:01 -0700, Chris Halcrow
<Ch**********@discussions.microsoft.comwrote:
[...]
<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
Jul 25 '08 #6

P: n/a
On Thu, 24 Jul 2008 17:42:03 -0700, Chris Halcrow
<Ch**********@discussions.microsoft.comwrote:
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?
Not off-hand, no. Sorry. I'm sure I couldn't find it any faster than you
could yourself, but I do know I've seen mention of it in this newsgroup,
so you might start by searching this newsgroup for those mentions (you
might try using the Google Groups archive, rather than Microsoft's portal,
if the Microsoft search isn't flexible enough).

Pete
Jul 25 '08 #7

P: n/a
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.

--
Happy Hacking,
Gaurav Vaish | http://dwt.sourceforge.net
http://blogs.mastergaurav.com | http://eduzine.edujini-labs.com
--------------------------------


Jul 27 '08 #8

P: n/a
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 <litag

<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)" wrote:
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.

--
Happy Hacking,
Gaurav Vaish | http://dwt.sourceforge.net
http://blogs.mastergaurav.com | http://eduzine.edujini-labs.com
--------------------------------


Jul 28 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.