|
Hello,
I first created a class called BreadCrumbs.cs. Here is a snippet of code...
***Portion of BreadCrumbs.cs code***
namespace Sabre_Solutions
{
///
/// Summary description for BreadCrumbs.
///
public class ctrlBreadCrumbs:System.Web.UI.WebControls.WebControl
{
public string Separator = ">";
public string RootName = "Home Page";
public char directoryNameSpacer = '_';
private string _PageTitle;
public string PageTitle
{
get
{
***and so on...****
Okay, second part. Created my own control called BreadCrumbs.ascx. This is its code (in entirety)
***code for BreadCrumbs.ascx
<%@ Register TagPrefix = "bc" Namespace = "Sabre_Solutions" Assembly = "BreadCrumbs"%>
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="BreadCrumbs.ascx.cs" Inherits="Sabre_Solutions.BreadCrumbs" %>
****End .asxc***
Part three, the code behind..
****BreadCrumbs.asc.cs*******
namespace Sabre_Solutions
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using System.Text;
///
/// Summary description for BreadCrumbs.
///
public class BreadCrumbs : System.Web.UI.UserControl
{
protected ctrlBreadCrumbs bc1;
private string _strHeaderText;
public string HeaderText
{
get
{
return _strHeaderText;
}
set
{
_strHeaderText = value;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
bc1.PageTitle = HeaderText;
}
***and so on...***
So the question. Everything compiles correctly, but when I drop the control into an .aspx file and try to run I get this error:
The base class includes the field 'bc1', but its type (Sabre_Solutions.ctrlBreadCrumbs) is not compatible with the type of control (Sabre_Solutions.ctrlBreadCrumbs).
I've been searching online and it seems to be a common problem, but none of the answers were on point (for me anyhow). I've tried changing a number of things but with no luck. I'm sure it's something small...can anyone see it?
-- modified at 14:35 Monday 8th May, 2006
|
|
|
|
|
***Portion of BreadCrumbs.cs code***
namespace Sabre_Solutions
{
///
/// Summary description for BreadCrumbs.
///
public class ctrlBreadCrumbs:System.Web.UI.WebControls.WebControl
{
public string Separator = ">";
public string RootName = "Home Page";
public char directoryNameSpacer = '_';
private string _PageTitle;
public string PageTitle
{
get
{
***and so on...****
Okay, second part. Created my own control called BreadCrumbs.ascx. This is its code (in entirety)
***code for BreadCrumbs.ascx
<%@ Register TagPrefix = "bc" Namespace = "Sabre_Solutions" Assembly = "BreadCrumbs"%>
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="BreadCrumbs.ascx.cs" Inherits="Sabre_Solutions.BreadCrumbs" %>
****End .asxc***
Part three, the code behind..
****BreadCrumbs.asc.cs*******
namespace Sabre_Solutions
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using System.Text;
///
/// Summary description for BreadCrumbs.
///
public class BreadCrumbs : System.Web.UI.UserControl
{
protected ctrlBreadCrumbs bc1;
private string _strHeaderText;
public string HeaderText
{
get
{
return _strHeaderText;
}
set
{
_strHeaderText = value;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
bc1.PageTitle = HeaderText;
}
***and so on...***
It seems to me that your base class should inherit usercontrol not web control. Then your usercontrol codefile should inhert the base class.
Like this
//Base class
public class ctrlBreadCrumbs:System.Web.UI.UserControl
{
}
//User Control
public class BreadCrumbs : ctrlBreadCrumbs
{
}
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
ToddHileHoffer wrote: It seems to me that your base class should inherit usercontrol not web control. Then your usercontrol codefile should inhert the base class.
Like this
//Base class
public class ctrlBreadCrumbs:System.Web.UI.UserControl
{
}
//User Control
public class BreadCrumbs : ctrlBreadCrumbs
{
}
Okay, made those changes. So my snippets look like this...
***BreadCrumbs.cs***
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Text;
using System.Web;
namespace Sabre_Solutions
{
///
/// Summary description for BreadCrumbs.
///
public class ctrlBreadCrumbs:System.Web.UI.UserControl
{
public string Separator = ">";
public string RootName = "Home Page";
public char directoryNameSpacer = '_';
private string _PageTitle;
public string PageTitle
{
get
***and so on***
***Breadcrumbs.ascx***
<%@ Register TagPrefix = "bc" Namespace = "Sabre_Solutions" Assembly = "BreadCrumbs"%>
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="BreadCrumbs.ascx.cs" Inherits="Sabre_Solutions.BreadCrumbs" %>
<bc:ctrlbreadcrumbs id="bc1" runat="server">
***END***
***BreadCrumbs.ascx.cs***
namespace Sabre_Solutions
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using System.Text;
///
/// Summary description for BreadCrumbs.
///
public class BreadCrumbs : ctrlBreadCrumbs
{
protected BreadCrumbs bc1;
private string _strHeaderText;
public string HeaderText
{
get
{
return _strHeaderText;
}
set
***and so one****
Now, when I compile I get the following error:
c:\inetpub\wwwroot\Sabre Solutions\BreadCrumbs.ascx.cs(16): 'Sabre_Solutions.ctrlBreadCrumbs' is defined in multiple places; using definition from 'c:\inetpub\wwwroot\Sabre Solutions\BreadCrumbs.cs' (I bolded the line it's referencing.)
Just for giggles I tried to run just the .aspx form that has the control. I still get the error but it's slightly different...
The base class includes the field 'bc1', but its type (Sabre_Solutions.BreadCrumbs) is not compatible with the type of control (Sabre_Solutions.ctrlBreadCrumbs
Any other ideas? My brain is fried at this point.
|
|
|
|
|
How to connect Active Directory using LDAP? The code should work in ASP and ASP.Net.
Thanks for your help.
|
|
|
|
|
public bool AuthenticateUser(string domain, string username, string password)
{ string LDAPPATH ="LDAP://appserver.com";
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry( "LDAP://appServer.com", domainAndUsername, password);
try
{
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResultCollection result = search.FindAll();
if( result.Count==0)
{
return false;
}
}
"Aim to go where U have never been B4 and Strive to achieve it"
http://groups.yahoo.com/subscribe/dotnetforfreshers
http://himabinduvejella.blogspot.com
-- modified at 4:42 Tuesday 9th May, 2006
|
|
|
|
|
Hi Himabindu,
Thank you for your code, but what I need is the code should work in both ASP and ASP.Net. Without using directory services it should work in both.
for ex. in ASP
strADsPath = "LDAP://strservername/DC=xxx,DC=com"
Set objldap = GetObject(strObjectADsPath)
objldap.GetInfo
above code will work in ASP but how to execute same code in asp.net
|
|
|
|
|
I get this error: "Invalid attempt to FieldCount when reader is closed." on the databind() method when the following code is run:
Private Sub loadProject()
Dim objDR As SqlDataReader
Dim objConn As New SqlConnection(strConn)
Dim objSQL As New SqlCommand("SELECT * FROM Projects ORDER BY Priority DESC, ProjectID DESC", objConn)
objConn.Open()
objDR = objSQL.ExecuteReader
grdDisplay.DataSource = objDR
grdDisplay.DataBind() <--Error occurs here
If grdDisplay.Items.Count = 0 Then
grdDisplay.Visible = False
lblMessage.Text = "No projects found."
Else
grdDisplay.Visible = True
End If
objDR.Close()
objConn.Close()
End Sub
This code is called directly from the Page_Load event on the first page after login so there are no prior database calls that could close the connection. When I step through the code in VS the autos window shows the objDR IsClosed property is FALSE at the time the databind() method is called.
This same code (different SQL strings) works fine everywhere else in the app. Also it has been working fine all along and just simply stopped working. The only change I made was moving the database and thus adjusting the connection string (which works fine elsewhere.
What am I missing?
Thank you in advance for any suggestions!
Peter
-- modified at 14:37 Monday 8th May, 2006
|
|
|
|
|
Try this.
Private Sub loadProject()
Dim objDR As SqlDataReader
Dim objConn As New SqlConnection(strConn)
Dim objSQL As New SqlCommand("SELECT * FROM Projects ORDER BY Priority DESC, ProjectID DESC", objConn)
objConn.Open()
objDR = objSQL.ExecuteReader
grdDisplay.DataSource = objDR
grdDisplay.DataBind() <--Error occurs here
objDR.Close()
objConn.Close()
If grdDisplay.Items.Count = 0 Then
grdDisplay.Visible = False
lblMessage.Text = "No projects found."
Else
grdDisplay.Visible = True
End If
End Sub
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
Thanks for the suggestion - however I still get the same error. This error occurs on both my development laptop, and on my internal test server.
|
|
|
|
|
How is your grid set up? I bet you are attempting to bind to columnName not returned in your query. Remember the fieldnames are case sensitve. Also, try not using * but rather listing the fields.
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
Thanks! You forced me to review the datagrid setup and of course I realized that I have an embedded datagrid that lists project tasks, and of course it was throwing the error, not the parent datagrid().
Sometimes you cant see the forest through the trees.
|
|
|
|
|
I use MS Studio to coding the asp.net, i need to perform some action if the user close the web page, i try page_unload before but cannot function. So, may i know where i should put my code for the coding page, when the user close the page and some action fired?
|
|
|
|
|
The page unload is the event on the code behind not the client. You can't really run server code when the browser closes. You can however, run code in the global.asax for the Session_End event.
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
Well you can call some server-side code using AJAX in the onBeforeUnLoad
--------------------------------------------------------
My portfolio & development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
This is a difficult one. You can add a javascript function to the body (onunload). The only problem you have is that this function will fire before postback as well. You will have to pull some trick of setting a javascript variable that controls the function.
You won't be able to do server side processing, because the page will not do a request when you close it. Well I think so. If that is wrong, can someone please correct me.
TMF
|
|
|
|
|
Use Window.unload Event of the Javascript
"Aim to go where U have never been B4 and Strive to achieve it"
http://groups.yahoo.com/subscribe/dotnetforfreshers
http://himabinduvejella.blogspot.com
|
|
|
|
|
Hi,
just write the following javascript function
function closeIt()
{
event.returnValue="closing";
}
and write the following in Html body
Let me know if you have any questions.
Thanks,
Bhasker P
|
|
|
|
|
Hi this is more a question about appearance than anything. I have a check box list which I want to divide up as follows. 3 Items followed by a heading followed by another 3 items heading and so on. But all the items are the same list. Can this be done? Thanks in advance
|
|
|
|
|
You need to be a little creative. I would suggest creating a user control formatted the way you want. Then pass the user control the heading and dataset (3 records). Use the loadcontrol option to dynamically add them to your page. Or have a dropdownlist that filters the checkbox.
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
String.Format("{000:N}", maxNumberFound)
maxNumberFound is = 3
and I want it to display as "003".
anyone know how without string manipulation.
Thanks,
Nick
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
|
Yeah I used ToString to format it.
I tried deleting it, but could find the topic.
Thanks tho
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
Did you already resolve this?
If not, try this:
String.Format ("{0:D3}", maxNumberFound)
Jon Sagara
When I grow up, I'm changing my name to Joe Kickass!
My Site | My Blog | My Articles
-- modified at 13:07 Monday 8th May, 2006
|
|
|
|
|
actually yes.
Jon Sagara wrote: String.Format ("{0:D3}", maxNumberFound)
Unfortunately, that just returns "3.00" I used d5.
But the ToString has an override that I can say "000" and it will form correctly.
Thanks for helping tho.
Nick
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
Ista wrote: Unfortunately, that just returns "3.00" I used d5.
That's weird. Maybe it's a difference of UI cultures that causes that. On my system it returns "003".
Oh well. Glad you got it sorted.
Jon Sagara
When I grow up, I'm changing my name to Joe Kickass!
My Site | My Blog | My Articles
|
|
|
|