Link to home
Start Free TrialLog in
Avatar of FairyBusiness
FairyBusinessFlag for United States of America

asked on

How to display my c# code on an asp page?

Hi, I am trying to test my server and have the results display on a test page:

test.aspx
<asp:Literal ID="includeLiteral" runat="server" />

test.aspx.cs
includeLiteral.Text = Main();

But its not working. Can someone help me display c# code in my webpage?

http://auroriella.com/test.aspx


test.aspx
test.aspx.cs
Avatar of kaufmed
kaufmed
Flag of United States of America image

You are trying to display the return value from a function whose return type is void--meaning there is no return type. Why are you defining a console application inside of your web application to begin with? What is the overall goal?
Avatar of FairyBusiness

ASKER

Oh, I didnt realize I was lol.  How can you tell its a console application?  I was following a tutorial to test the server connection to my database.  I am trying to out put information from my Users table in my sql server database.

SqlCommand cmd = new SqlCommand("select * from Users", conn);
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't have a name space currently. Does it matter what I choose to name it?
Why is my id coming up not recognized?
includeLiteral.png
I defined includeLiteral as an id in my test.aspx file, shouldn't that be enough???
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't see that option:
app.png
Sorry, please disregard the last suggestion. You made a web site, not a web application.

Your new error is my fault, any way. I gave you a class name of "_Default", but that is not correct. Change "class _Default" to "class test".
ok I renamed the class but its still has a red underline and my webpage still doe not work.

Is it better to make a web application versus a website?


test.png
so the class name has to match the aspx file name?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
so the class name has to match the aspx file name?
AFAIK, no. It just needs to match what you put in the Inherits attribute of the Page directive.
1. Is a namespace really necessary?  Without it could I just have Inherits="test"  ?

2. I am not getting any errors in visual studio, but when I try to run the page in the browser it does not work still.  Any ideas as to why?

http://auroriella.com/test.aspx
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
when I try to run the page in the browser it does not work still.  Any ideas as to why?
What does the page say is the error when you view it in the browser?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I really like your examples of the namespaces.  I remember back in php I would want to have two functions named the same things but do different things and be used in different situations but I couldn't! I think this will come in handy :)

Here's what it says in the browser:

http://auroriella.com/test.aspx

it has a problem with line 30 but I don't know why.. .
line30.png
Did you add a connection string to your web.config file? The structure should be similar to:

<configuration>
    <connectionStrings>
      <add name="connection"
           connectionString="your connection string here"
           providerName="System.Data.SqlClient" /> <!-- the provider may change if you're not using SQL Server -->

    </connectionStrings>
</configuration>

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok, I took away the first one entirely but still the same error message in the browser :(
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yep its all correct, that's why I'm stumped
Does you database server use Windows authentication or SQL Server authentication?
Windows authentication
might having problem with connection to the server create a good connection string

using,
http://www.connectionstrings.com/


and check for your authentication on demo application...
and if work then implement it on website..

Regards,
nishant
I had to end up getting information from my hosting site.  Besides that your info was great :)