FairyBusiness
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
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
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?
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);
SqlCommand cmd = new SqlCommand("select * from Users", conn);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I don't have a name space currently. Does it matter what I choose to name it?
ASKER
Why is my id coming up not recognized?
includeLiteral.png
includeLiteral.png
ASKER
I defined includeLiteral as an id in my test.aspx file, shouldn't that be enough???
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I don't see that option:
app.png
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".
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".
ASKER
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
Is it better to make a web application versus a website?
test.png
ASKER
so the class name has to match the aspx file name?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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>
ASKER
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok, I took away the first one entirely but still the same error message in the browser :(
ASKER
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yep its all correct, that's why I'm stumped
ASKER
Does you database server use Windows authentication or SQL Server authentication?
ASKER
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
using,
http://www.connectionstrings.com/
and check for your authentication on demo application...
and if work then implement it on website..
Regards,
nishant
ASKER
I had to end up getting information from my hosting site. Besides that your info was great :)