Hello guys, I wonder if anybody could clarify this for me. I've created a new website (File > New > Web site) and as we all know I now have a aspx file (Default.aspx) and a aspx.cs file (Default.aspx.cs). The aspx file contains a form and when submitted, it sends some data to a small SQL table. What I would like to do is to create another page (web page, aspx file - I don't know, whatever) to display the data saved in the SQL table, so that I essentially end up with two pages: one which allows you to submit the info to the database and another one that displays that content. I have to say that my knowledge of asp.net, visual studio and SQL is very basic, so I tried to add a new item by clicking on the project (I seem to understand that a web form is another aspx file) but there is a problem: ideally, I will need to use the same aspx.cs file (with the addition of the relevant code to display the database content of course) to retrieve the information from the SQL table rather than write the C# code in a separate aspx.cs file. Is that possible? I kind of assumed it was and so in my second aspx file (Results.aspx) I included ...CodeFile="Default.aspx.cs" Inherits="Default"...
so that it uses the same aspx.cs file, but the compiler didn't like it. So, my assumption might be wrong after all. Anyway, any suggestion as to what to do to achieve the above? Am I heading in the completely wrong direction?
thanks
Violet_82
89
Posting Whiz in Training
Recommended Answers
Jump to PostAm I heading in the completely wrong direction?
If both pages share code, IMO the best option would be to create a class that does the actual work. You can then use that class in both pages.
An other option would be to create a base page (parent …
Jump to PostIf you add a new class to your project, then both aspx pages will know it exists. You can then create an instance in the page load and use it where needed.
I don't think you want to link two aspx pages to the same cs file, I don't really …
All 7 Replies
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
Violet_82
89
Posting Whiz in Training
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
JorgeM
958
Problem Solver
Team Colleague
Featured Poster
Violet_82
89
Posting Whiz in Training
JorgeM
958
Problem Solver
Team Colleague
Featured Poster
Violet_82
89
Posting Whiz in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.