|
Please clarify the references for each project.
Technically, you should reference both Core and Data projects in your main project.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
It sounds like you have a circular reference - OTF.Core depends on OTF.Data , and OTF.Data depends on OTF.Core .
You should refactor your code to remove that cycle from your dependency graph.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I know html, css some fundamentals of js and C#, and I have decided to delve into the world of asp.net. I have learnt that there are two options to begin with, razor pages and mvc. But Razor pages seem to have very little future at present.
Which is better, Razor pages or MVC to begin with? I am only 19 and I want to devote my life to coding
|
|
|
|
|
It sort of depends on your level of experience. If you are fairly skilled at building websites then go straight to MVC. If you are still a little unsure of things then start with Razor (as am I).
|
|
|
|
|
Whichever one you pick, there'll be a new "best" option every 5 years or so.
Concentrate on the fundamentals, and you should be able to transfer your skills to the next "Shiny New Thing" relatively easily.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am very new to ASP.net and C#, so I am trying my best, but there are stille many things that confuse me, especially because when I am looking at various examples online they give me different answers to the same solution, which just makes it even more confusing.
I made a person class, with two subclasses (driver and admin), but I can not get the ArrayList to show up when I run my Index file. I only get a parse error.
What do I need to change to make this work?
My person class
public class Person
{
public Person(string firstName, string lastName, int age, string email)
{
FirstName = firstName;
LastName = lastName;
Age = age;
Email = email;
}
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public string Email { get; }
public virtual bool ChangeEmail(string email)
{
Email = email;
return true;
}
public override string ToString()
{
return $"Name: {FirstName} {LastName}, Age: {Age}, E-mail: {Email}";
}
}
My subclasses
public class Driver : Person
{
private string v1;
private string v2;
private string v3;
private string v4;
private string v5;
public Driver(string firstName, string lastName, int age, string email, int
licenceNumber)
: base(firstName, lastName, age, email)
{
LicenceNumber = licenceNumber;
}
public Driver(string v1, string v2, string v3, string v4, string v5)
{
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
this.v4 = v4;
this.v5 = v5;
}
public int LicenceNumber { get; set; }
public override string ToString()
{
return $"Role: Traindriver, LicenceNumber: {LicenceNumber}, " + base.ToString();
}
}
public class Admin : Person
{
public Admin(string firstName, string lastName, int age, string email)
: base(firstName, lastName, age, email)
{
}
public override bool ChangeEmail(string email)
{
if (!email.EndsWith("@pig.dk", StringComparison.InvariantCultureIgnoreCase))
return false;
return base.ChangeEmail(email);
}
public override string ToString()
{
return $"Role: Admin, " + base.ToString();
}
}
}
My ArrayList
namespace Pig
{
public partial class Index : System.Web.UI.Page
{
public object ListBoxResults { get; private set; }
public object DriverListBox { get; private set; }
protected void Page_Load(object sender, EventArgs e)
{
Driver d1 = new Driver("Hans", "Christensen", 32, "hans@pig.dk", 123456);
Driver d2 = new Driver("Peter", "Jensen", 40, "peter@mail.dk", 123456);
Admin a1 = new Admin("Lene", "Maarud", 55, "lene@pig.dk");
ArrayList person = new ArrayList();
ListBoxResults.Items.Add(d1.ToString());
ListBoxResults.Items.Add(d2.ToString());
ListBoxResults.Items.Add(a1.ToString());
}
}
}
My Index file
<pre><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs"
Inherits="ThePig.index" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBoxResults" runat="server" Height="800px"
Width="600px"></asp:ListBox>
</div>
</form>
</body>
</html>
|
|
|
|
|
Please indicate the exact error message, as well as the line which is triggering it. "Not working" is not precise enough.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
You have a control with the ID ListBoxResults , which will automatically generate a field in your class:
private ListBox ListBoxResults; You have also declared a property called ListBoxResults in your code-behind.
I'd be extremely surprised if that code compiled; if it did, your references to ListBoxResults in your Page_Load method would be referring to the property, not the control.
Remove the property and your code should start working:
namespace Pig
{
public partial class Index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Driver d1 = new Driver("Hans", "Christensen", 32, "hans@pig.dk", 123456);
Driver d2 = new Driver("Peter", "Jensen", 40, "peter@mail.dk", 123456);
Admin a1 = new Admin("Lene", "Maarud", 55, "lene@pig.dk");
ListBoxResults.Items.Add(d1.ToString());
ListBoxResults.Items.Add(d2.ToString());
ListBoxResults.Items.Add(a1.ToString());
}
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Okay, I removed the property and also changed "ListBoxResults" to simply "ListBox".
There are some problems remaining.
I will list the errors here (sorry for not doing so at first)
ListBox.Items.Add(d1.ToString());
ListBox.Items.Add(d2.ToString());
ListBox.Items.Add(a1.ToString());
Here I get the error: "An object reference is required for the non-static field, method, or property."
If I remember correctly, a solution to this would be to make a static ArrayList, but I am not sure how I can do it for this code.
Error no. 2
<pre lang="c#">public virtual bool ChangeEmail(string email)
{
Email = email;
return true;
}
Error: "Property or indexer cannot be assigned to -- it is read only"
Error no. 3
public Driver(string v1, string v2, string v3, string v4, string v5)
{
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
this.v4 = v4;
this.v5 = v5;
}
Error message: There is no argument given that corresponds to the required formal parameter of 'firstName' of 'Person.Person (string, string, int, string)'
Thanks a ton for being patient with me, you guys.
|
|
|
|
|
Member 14671427 wrote: and also changed "ListBoxResults" to simply "ListBox"
Which is not what I said, and is the cause of the "object reference required" errors.
Remove the property; leave the Page_Load method as I showed you:
namespace Pig
{
public partial class Index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Driver d1 = new Driver("Hans", "Christensen", 32, "hans@pig.dk", 123456);
Driver d2 = new Driver("Peter", "Jensen", 40, "peter@mail.dk", 123456);
Admin a1 = new Admin("Lene", "Maarud", 55, "lene@pig.dk");
ListBoxResults.Items.Add(d1.ToString());
ListBoxResults.Items.Add(d2.ToString());
ListBoxResults.Items.Add(a1.ToString());
}
}
}
Member 14671427 wrote: Error: "Property or indexer cannot be assigned to -- it is read only"
You haven't added a setter to the Email property, so you can't set it.
If you don't want to be able to change it from outside of the class, then make the setter private :
public string Email { get; private set; }
Member 14671427 wrote: There is no argument given that corresponds to the required formal parameter of 'firstName' of 'Person.Person (string, string, int, string)'
Your Person constructor requires four arguments. Every constructor of a class derived from Person must pass those four arguments into the base constructor.
public Driver(string v1, string v2, string v3, string v4, string v5)
: base("??? FIRST NAME ???", "??? LAST NAME ???", 0, "??? EMAIL ???")
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi again and thanks once again.
I did do ask you said. The reason why I tried playing around with the ListBox line is because I am getting an CS0103 error: "The name ListBoxResults does not exist in the current context", which I don't get, because I looked in my index file.
It says
<asp:ListBox ID="ListBoxResults" runat="server" Height="800px" Width="600px"></asp:ListBox>
I checked if the namespace was the issue, but that was not that case.
However, the object reference error is gone, just like you said =)
|
|
|
|
|
That would suggest that your .aspx markup file isn't correctly tied to your .aspx.cs code-behind file.
Check the CodeFile / CodeBehind and Inherits attributes on the <%@ Page ... %> directive in your markup file.
@ Page | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Ah, what an idiot I was. In Inhereits, I had written "index" instead of "Index".
Thanks a lot for helping me =)
|
|
|
|
|
Hi Friends,
I have migrated asp.net 2.0 VS 2005 application to VS 2015 (framework 4.5).
Site loading fine. But when i click on the menus available in the page, actually it is not adding localhost in the redirection url.
for Eg:
My Home Page : http://localhost:1087/CGP/Home/Home.aspx. This page is loading fine.
In this page I have side menus and each menu "Profile" will have hyperlink like : CGP/Emp/Profile.aspx
But when I click on the menu "Profile" it is redirecting to http://CGP/Home/Home.aspx.
The term localhost is missing. I am not sure how to handle this.
Please Suggest.
Thanks and Regards
|
|
|
|
|
We'll probably need to see the code you're using to generate the side menu. But at a guess, you should add "~/" to the start of the URL.
So instead of:
NavigateUrl="CGP/Emp/Profile.aspx" use:
NavigateUrl="~/CGP/Emp/Profile.aspx"
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
.
modified 20-Nov-19 22:29pm.
|
|
|
|
|
Don't post your question in multiple forums. It's annoying, and it's not like people who look at this forum never come in the webdevelopment-forum.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hello Friends,
i have following code. I am getting Error "The SqlParameterCollection only accepts non-null SqlParameter type objects, not SqlParameter[] objects."
in the line
cmd.Parameters.Add(HasPermissionParams).
Please help.
Thanks in Advance.
SqlCommand cmd = GetCommand(Sql_GetPermission);
SqlParameter[] HasPermissionParams = GetInsertParameters(Sql_GetPermission);
SetHasPermissionParams(HasPermissionParams, EmpID, Permission);
cmd.Parameters.Add(HasPermissionParams);
private static void SetHasPermissionParams(SqlParameter[] parms, string EmpID, string Permission)
{
parms[0].Value = EmpID;
parms[1].Value = Permission;
}
private const string Sql_GetPermission = "[sp_Permission]";
private static SqlParameter[] GetInsertParameters(string querytype)
{
SqlParameter[] parms = null;
switch (querytype)
{
case Sql_GetPermission:
parms = new SqlParameter[]
{
new SqlParameter("@EmpID", SqlDbType.VarChar),
new SqlParameter("@PermissionName", SqlDbType.VarChar)
};
break;
}
return parms;
}
|
|
|
|
|
|
|
I've been developing in ASP.Net for over 12 years and, though it was a bit of a learning curve to start, feel the webforms environment is, for most purposes, pretty good. When MVC came on the scene (first via 3rd parties such as Castle's, then through MS's own offering) everyone pretty much jumped ship declaring it the best thing since sliced bread. As I had a commitment to supporting a number of webforms applications, I didn't initially have any need to switch; and subsequently haven't found any compelling reason to do so. I've looked (briefly, admittedly) at MVC but felt it was a steep learning curve and didn't seem to offer any advantages, and have some actual disadvantages, to what I was used to.
I answered a question in Q+A today where I mentioned Webforms, and the need to decide whether to go webforms or MVC, and a subsequent comment was "I will not recommend webforms".
So I'm curious: what is it about MVC that makes it so much better than webforms? Is it simply that it's flavour of the month and commercial requirements for webforms developers has crashed? (plug: I have a requirement for a webforms maintenance developer ... message me for more details)
Is it that MVC is a lot "better", or do people feel webforms is actively "bad"?
My applications, using webforms, successfully separate business functionality from presentation issues (and indeed database/storage access from business objects). They implement multi-level inheritance, use custom controls to implement standard functionality, incorporate AJAX-based interactive features (not using Microsoft AJAX controls); and have proven to be flexible and extensible. Not yet found anything I can't do with Webforms.
|
|
|
|
|
Guess I must be the biggest opponent of WebForms here, even as far as calling it stupid.
What I didn't like?
Didn't like the way they tried to make it like WinForms, in which objects create HTML. So you create all these labels which are just span tags. Then when you go to port your HTML to another framework, you have to change all the objects back to actual HTML. As a negative effect, you never really master HTML or HTML5. If you stick with WebForms and not move forward, you stay stuck in that world of objects for years, never really moving forward to support phones, tablets and desktops.
I also got burned by the Ajax Control Toolkit. It worked great locally, but failed on long distance connections. The Partial Update control worked the same way. They added so much junk that was never really stable. Perhaps a WebForms app written for in-house use might be OK, but not for world wide production use. And then all of this stuff has to play nice with the Web Server such as IIS. It seems like WebForms with it's ViewState worked tightly with IIS server in order to post data back, and IIS server would have to keep track of every session out there.
Google just didn't play nice with WebForms. WebForms had a way of placing a script on the page, and using a weird URL for it's location that Google didn't like. I think it was a query-string added to the script name. Then Google complained about other elements I had no control over. And then the single use of the Form element, and having to work within that parameter or rule.
I could name probably 10 more things I didn't like about it.
Moving Forward
I dumped WebForms and went MVC, and loved it. After the steep learning curve, I was able to reduce the time for new projects in half. Learned how to write very effective models and are close to my database designs. With views and razor, I was able to create new UI that where more user friendly, and much more fluid. Learned Gulp to package my CSS and compress files.
Then I dumped MVC and went .Net Core MVC loving it even more. Delivering blazing fast speeds but I still didn't care for Razor much. But my SEO tests were off the charts and Google loved it.
Last, I took the Angular jump, Angular wrapped in a .Net Core project. Figured out how to pack all my stuff like SASS, and compile it into a single project that runs in a Docker container. With this technology, I can now focus on providing a great user experience, with super efficient models and database designs, with blazing fast speeds. I spend very time writing code, in which most are just a few lines. I don't have to worry about slow connections any more.
Now I can develop in 1/16 the amount of time it took me in WinForms. My website below is version 298 at the moment. I have no regrets at all about leaving WebForms, even MVC as well. The WebPack train is running and lots of people are hopping on the train.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Convincing arguments, and a very nice site that would shame many a company
..but "There just fine for low volume entry level use in which you get a few visitors a week."? Isn't that "they are just fine"?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Thanks Eddie!
Maybe I spoke too soon, one of my Docker MongoDB container crashed. First time in 7 months since I figured out how to use Docker that any container has crashed. 7 months uptime is not bad.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
jkirkerx wrote: Maybe I spoke too soon, one of my Docker MongoDB container crashed. It's the demo-effect; post a link on CP, and soon you get a lot of posts pointing out what is wrong
It looks clean, is readable, contains an impressive list of clients and reviews. No weird font/color combinations, not much distractions in animations, and only one popup
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|