basic help on .net

mallasani
mallasani used Ask the Experts™
on
Q1)How to post data from a ASP.NET form
  (for eg : user registration form)
Q2) How to read that data into C# file
Q3) How to send data back to ASP.NET from an C# file
Q4) How to pass data between two ASP.NET pages
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Ok I'll have a go at your questions. You have to realise that ASP.NET and C#/VB.net code go hand in hand together, they work as a team.

Q1) define your controls (textboxs, buttons) as server controls. If your using Visual Studio.NET then the controls are set to server by default.
Heres an example of the ASP.NET code generated.

<asp:button id="btnSearch" style="Z-INDEX: 103; LEFT: 15px; POSITION: absolute; TOP: 206px" runat="server" Text="Search"></asp:button>

When someone clicks on your button, it will fire a postback to the server and then jump into the event handler for the button. This leads to your 2nd Question.

Q2) Now that the user has clicked your button, the post back has occurred and your now in the Click event for the button you can start gathering the form data.

You can reference and access any of the data that is held in any of your server controls quite easily.

 eg String MyString = MyTextBox.Text;

This will assign what ever is in the textbox to your string variable (basically whatever the user has typed in there)

Q3) If you had defined a label somewhere on your page to be used for user messages perhaps, during the button's click event you could set this label's text to something and then when the button's click event is finished and the screen is refreshed and this information is sent to the user.
eg. MyLabel.Text = "Invalid Password".

Q4)
Heres one way to pass data between 2 ASP.NET pages.

private button1_Click(object sender,System.EventArgs e)
{

String UserID = txtUserID.Text;

Response.Redirect("UserDetails.aspx?userID=" + System.Web.HttpUtility.UrlEncode(UserID));

}

Hope it helps.
Joe

Author

Commented:
yeah it's great help, before accepting your answers, i would like to request you for any sample code you have.
I wanna create a ASP.NET page and post data, based on operation i need to access differnt C# files to handle database transaction and i need to send back the result to ASP.NET page to disply on browser. Please help me out.
Commented:
These different C# files.... what do they contain?? Are they doing the database transactions for you??? Are these C# files classes that you have access to ???

Heres a sorta pseudo code example process on what I have done in one instance.

I do all my Database transactions in a seperate C# Class (different C# file)

1. Create a ASP.NET applicaition and add a few textboxes and a ok button and a label to relay any messages back to the user. (I named mine txtUserID, txtPassword, btnOK, lblMessage)

2. If you use Visual Studio.NET you can just double click on the button in the form designer and it will take you to the C# code for that button's click event.

3. In the btnOK click event, read the information from the textboxes. (Remember, when a postback occurs, the data from the controls are sent back to the server)

my code looks something like

private void btnOK_Click(object sender,System.EventArgs e)
{
     MyDataBaseClass _myDBClass = new MyDataBaseClass();
     bool bLogonOK = _myDBClass.IsUserValid(txtUserID.Text,txtPassword.Text);
     if(bLogonOK != true)
     {
         lblMessage.Text = "Invalid Logon. Please Try Again.";
         txtUserID.Text = "";
         txtPassword.Text = "";
     }
     else
     {
          Response.Redirect("UserDetails.aspx?userID=" + System.Web.HttpUtility.UrlEncode(UserID));

      }

}

if you want to display rows of information from your database. The simplest way would be to populate a DataSet with the results and then use the DataSet as a source for a DataGrid object.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial