?
Solved

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

Posted on 2014-01-14
8
Medium Priority
?
26 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

764 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