Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools

William Konig
PLUS
William Konig
Courses Plus Student 910 Points

connecting to c# in visual studio

I have a css file a javascript file, html file and a visual studio (c#) Project all on the same server. How do I tell visual studio project to use the html file when it has a designer that generates html. (2) And in maintenance you check it out how do you add a button you need to add code for.

What is the procedure to do both.

Please show code if needed

HI Steven

That worked . I have my own copy of visual studio. I need to add a sever side button and place the output from table in a textbox

my code for the button is

<asp:Button ID="Button1" runat="server" Text="Button" />

which is not valid . How would you code it.

4 Answers

James Churchill
STAFF
James Churchill
Treehouse Teacher

William,

As Steven mentioned in his reply, it looks like you're trying to create an ASP.NET Web Forms page. Unfortunately, we don't offer any courses or workshops on ASP.NET Web Forms. ASP.NET comes in another, newer flavor/form, known as ASP.NET MVC. If you'd like to learn more about how to use ASP.NET MVC, I'd recommend joining our Beginning ASP.NET track at https://teamtreehouse.com/tracks/beginning-aspnet.

If you'd like to learn more about ASP.NET Web Forms, I'd recommend taking a look at the tutorials that Microsoft provides at https://www.asp.net/web-forms.

Thanks ~James

Steven Parker
Steven Parker
231,198 Points

If you place your HTML file in the same folder as your C# project, the server should provide it to the client along with the generated files. The same with the CSS and JavaScript. You can add it to the project by right-clicking on the project name in the solution pane, then select "add", then "existing item", then pick your file with the chooser.

To add a button, while ediitng your file, open the "tools" window and drag "Input (Button)" into the edit window an release. The code will appear.

You can also add an actual "button" element but you'll need to type that code yourself since there's no toolbox entry for it.

William Konig
PLUS
William Konig
Courses Plus Student 910 Points

Hi Steven

What I did was added to visual studio the css and javascript then I pasted the html into the default page an left the tag <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> at the top. It all started working. So you would have to coordinate with the front end guy to determine which elements would be server side " let's say you had a server button that ran a stored proceduce to get some data to populate a grid. Would that be true or what would you recommend

Steven Parker
Steven Parker
231,198 Points

That header indicates that you've created an ASP.NET Web Forms file, not a plain HTML file. ASP code mixes front-end and and server code and must be converted by the server into plain HTML before it is sent to the front-end client (browser). It's a handy way to write for both ends in the same file. There will also be an associated .cs file that goes with it that is purely server code.

Perhaps that's what you want — ASP can be very useful but it has it's own learning curve.

William Konig
PLUS
William Konig
Courses Plus Student 910 Points

Hi Steven

Sorry about this. I am new to all of this. I put my html into htmlPage.htm . That is the default page visual studio generates It work fine for html controls. Now how would I add a server side grid element into it <asp:GridView ID="GridView1" runat="server"> /asp:GridView . So I can retrieve table data from a button click. How to add it . Please show any code if needed.

Thanks

Steven Parker
Steven Parker
231,198 Points

As I said, ASP has it's own learning curve. You'll probably need to take a few courses or tutorials on ASP.NET Web Forms if you're not already familiar with it.