How do I retrieve inputs from web, return results to web page?

G

Guest

How do I retrieve user inputs from web page into the C# program that is
running behind? I am using Visual Studio to create an ASP.NET web
application with code behind (aspx.cs) feature. Also, how do I post the
results from the C# program on the web Page? I need a code example in
C# so I can get the syntax right.

THANKS!!!
Craig/Stephanie
 
R

Ray Costanzo [MVP]

aspx snippet:
<form runat="server">
<asp:textbox id="theTextbox" runat="server" />
</form>

cs snippet:
string s = theTextbox.Text;

Ray at work
 
S

swheeler6

Ray,
Thank you for your reply. Do I use "string s" for all of my inputs,
even if they are integers?
Stephanie
 
M

Martin Randall

Sure as the text boxes accept text and have Text property to get access to
it. If what is entered is a number, you need to convert it from a string to
an integer using something like...

string enteredNumber = theTextBox.Text;
int number;
if ( Int32.TryParse( enteredNumber, out number ) )
{
// Do something with the number
} else {
// Display an error
}

Martin Randall
 
S

swheeler6

Martin,
Thank you for your suggestions, but I keep getting these errors:

c:\inetpub\wwwroot\webapplication3\webform1.aspx.cs(90,18): error
CS0117: 'string' does not contain a definition for 'Text'
c:\inetpub\wwwroot\webapplication3\webform1.aspx.cs(93,10): error
CS1502: The best overloaded method match for 'uint.Parse(string,
System.Globalization.NumberStyles)' has some invalid arguments
c:\inetpub\wwwroot\webapplication3\webform1.aspx.cs(93,33): error
CS1503: Argument '2': cannot convert from 'out uint' to
'System.Globalization.NumberStyles'

Also, when I try to use Response.Write, I get this error:

c:\inetpub\wwwroot\webapplication3\webform1.aspx.cs(405,5): error
CS0246: The type or namespace name 'Response' could not be found (are
you missing a using directive or an assembly reference?)

Thank you.
Stephanie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top