Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy does my asp.net page not using my c# method?
    primarykey
    data
    text
    <p>Hello i have a problem with my project. When I submit a creditcardnumber the program should normally jump into my servervalidation, execute the commands from my if instruction and jump into both bool methods but the program just went through the if instruction and jumps into the submitbutton method to show the result. What did I do wrong?</p> <p>here the code for the server:</p> <pre><code>protected void SubmitMidtermBtn_Click(object sender, EventArgs e) { this.OnMidtermInfoCollected(); } public void ServerValidation(object source, ServerValidateEventArgs args) { if (CardType(args.Value, CreditCardType.Text) &amp;&amp; IsCreditCardValid(args.Value)) { args.IsValid=true; } else { args.IsValid=false; } } public bool CardType(string cardNumber, string cardType) { if (cardType.Equals("VISA")) { if (cardNumber.Length == 14 || cardNumber.Length == 16 &amp;&amp; (cardNumber.StartsWith("4"))) { return true; } } if (cardType.Equals("Mastercard")) { if ( cardNumber.Length == 16 &amp;&amp; cardNumber.StartsWith("51") || cardNumber.StartsWith("52") || cardNumber.StartsWith("53") || cardNumber.StartsWith("54") || cardNumber.StartsWith("55")) { return true; } } if (cardType.Equals("AmericanExpress")) { if (cardNumber.Length == 15 &amp;&amp; cardNumber.StartsWith("34") || cardNumber.StartsWith("37")) { return true; } } if (cardType.Equals("Discover")) { if (cardNumber.Length == 16 &amp;&amp; cardNumber.StartsWith("601")) { return true; } } return false; } public bool IsCreditCardValid(string cardNumber) { int i; StringBuilder cleanNumber = new StringBuilder(); for (i = cleanNumber.Length + 1; i &lt;= 16; i++) cleanNumber.Insert(0, "0"); int multiplier, digit, sum, total = 0; string number = cleanNumber.ToString(); for (i = 1; i &lt;= 16; i++) { multiplier = 1 + (i % 2); digit = int.Parse(number.Substring(i - 1, 1)); sum = digit * multiplier; if (sum &gt; 9) sum -= 9; total += sum; } return (total % 10 == 0); } </code></pre> <p><em>this thing don't catch the last closing tag that should be at this place</em></p> <p>at this point the server validation should be activated:</p> <pre><code>&lt;asp:CustomValidator ID="CreditcardValidation" ControlToValidate="CreditCardNumber" OnServerValidate="ServerValidation" ErrorMessage="" runat="server" Display="Dynamic"&gt; &lt;div class="alert alert-danger"&gt;Please enter a valid creditcard number&lt;/div&gt; &lt;/asp:CustomValidator&gt; </code></pre> <p>can somebody please help me with that?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload