[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 33
  • Last Modified:

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

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
tonymm73
Asked:
tonymm73
  • 3
  • 3
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
tonymm73Author Commented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
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
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
tonymm73Author Commented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
Aijaz ChauhanCommented:
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
 
tonymm73Author Commented:
OK I will give this a try.  I will let you know shortly if it works.  Thanks for the Help.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now