Solved

Help with ASP.NET C# CodeBehind for a Button and two text box controls

Posted on 2014-01-14
8
20 Views
Last Modified: 2016-06-13
I have two text-boxes and one Submit button.  One text box is for account number and the other is for UID.  A user enters the account number in one and the UID in the other and when the button is clicked the entry is checked with the vendor number and UID in the database.  If the account number is correct the account information is displayed in a Detailview.  If the UID is correct the account is displayed in a DetailView.  If an incorrect account number is entered an error message is displayed.  An error message is displayed if the UID is not correct.  We are having problems with incorrect account numbers and UID numbers being entered.  The problem I am having is with the logic for the button code behind.  I know i need to use a else if in the codeBehind page for the click event but I keep getting an error.Below I have added the aspx page and the aspx.cs page.
OptimalAccountSearch.aspx
OptimalAccountSearch.aspx.cs
0
Comment
Question by:tonymm73
  • 3
  • 3
8 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39781631
What code have you tried? What error are you getting? Which specific part of the logic are you having trouble with, is it just the If...Else part, or the database access part as well?
0
 

Author Comment

by:tonymm73
ID: 39783439
I am only having an issue with the If else logic.  I can access the database and if you look at the detailsview controls you can see how I am doing this.  My problem is the If Else part of the button. Here is where I am getting confused.  The user can enter an account number in one textbox and UID in the other textbox.  If both are correct then the account for both are displayed using detailsView.  If one is correct then that one is displayed using detailsview and an error is shown in the textbox that isn't correct. I have been able to do a simple button that displays the detailsview but I am running in trouble with the error messages. This is where I am getting lost using the button.  I know that the code below isn't even close but maybe that will help with the logic.

public partial class OptimalAccountSearch : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnTransmitted_Click(object sender, EventArgs e)
        {            

            if (VendorAccountNumber not correct)
            {
                List error message
            }

            else
            {
                if (VendorAccountNumber correct)
                    txtAcctNumber = List detailsView;


                if (txtUIDnumber is not correct)
                 {
                   List error message
                 {
           else
                 if (UID correct)
                    txtUIDnumber = list detailsView;
            }
        }
    }
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39786220
So how are you determining if the account and UID numbers are correct or not? Are you just relying on an empty dataset being returned, or do you get a return status code?

Are you retrieving both sets of data with a single database call, or do you have two calls and two datasets, one for account and one for UID?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:tonymm73
ID: 39786834
When the user enters in a UID and vendor account number they are compared to the database.  

I am using DetailsView EmptyDataTemplate to display an error if the account number or UID isn't correct.  If you look at the OptimalAccountSearch.aspx page you won't see the WmptyDataTemplate because I just added it to the code..

I have two calls and two datasets (DetailsView).  This is the only way I could think of doing this incase  someone entered in a correct account number and UID but they are from two separate accounts.  With two datasets both accounts would be displayed.

Everything seems to work except the button click event after the numbers are entered into the text box's.


.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39787893
If you are using the EmptyDataTemplate, then you shouldn't really need any additional logic. If the UID is incorrect then you will get an empty dataset back from the database. Bind that to the detailsview and it will show the EmptyDataTemplate. So basically, the lack of any data is what indicates the account number is correct.

Or am I over-simplifying things?
0
 
LVL 2

Accepted Solution

by:
Aijaz Chauhan earned 500 total points
ID: 39793432
public partial class OptimalAccountSearch : System.Web.UI.Page
    {
       
        protected void btnTransmitted_Click(object sender, EventArgs e)
        {            

           bool IsValidAccountNumber=false;
           bool IsValidUID=false;
       
            if (VendorAccountNumber not correct)
            {
                List error message;

            }
            else
            {
                 IsValidAccountNumber=true;
            }

            if (VendorUID not correct)
            {
                List error message;

            }
            else
            {
                 IsValidUID=true;
            }
         
           if(IsValidAccountNumber==true && IsValidUID==true)
          {
                 //show detail view for Account Number
                 //show detail view for UID
           }

        }
    }


This solution works when account number and UID both are valid. If you want to display error for invalid result you can do minor change in this logic.


If you find any problem just let me know
Hope this helps.
0
 

Author Comment

by:tonymm73
ID: 39803027
OK I will give this a try.  I will let you know shortly if it works.  Thanks for the Help.
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question