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

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
aspx snippet:
<form runat="server">
<asp:textbox id="theTextbox" runat="server" />
</form>

cs snippet:
string s = theTextbox.Text;

Ray at work
 
Ray,
Thank you for your reply. Do I use "string s" for all of my inputs,
even if they are integers?
Stephanie
 
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
 
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
 
Back
Top