Solved

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

Posted on 2014-01-14
8
14 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:tonymm73
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
OK I will give this a try.  I will let you know shortly if it works.  Thanks for the Help.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now