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?
Jump to Post
Am 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 …
All 7 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.