Solved

C#8

Posted on 2012-03-17
5
225 Views
Last Modified: 2012-03-18
Can you help me to get this html to display on the server side?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
        <title>Paycheck</title>
  </head>
<body>
    <script runat="server" >
        void Text1_onclick(object sender, EventArgs e)
        {
           
        }
        void Text1_onclick(object sender, EventArgs e)
        {
        }
        void Submit1_onclick(object sender, EventArgs e) {
             if (Text1.Value.Length < 1)
             {
                string error = "Please Enter a value in Hours Field ";
                string script = "alert(\"" + error + "\");";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "myScript", script , true);

              }
            else if(Text2.Value.Length < 1)
             {
                string error = "Please Enter a value in Pay Rate Field";
                string script = "alert(\"" + error + "\");";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "myScript", script , true);

              }
            else
             {
                string error = Convert.ToDouble(Text1.Value);
                string error = Convert.ToDouble(Text2.Value);
                string script = "alert(\"" + "\");";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "myScript", script, true,
                "Your Gross Pay is $ {0}" ,hours - 40 * rate * 1.5);
             }
             }
       </script>
    <form action="Default.aspx" method="post" runat="server">
    <p>Enter Hours Worked:<input id="Text1" type="text" onServerClick="Text1_onClick" runat="server" /></p>
    <p>Enter Pay Rate:<input id="Text2" type="text" onServerClick="Text2_onClick" runat="server" /></p>
    <p><input id="Submit1" type="submit" value="submit" onServerClick="Submit1_onclick" runat="server" /></p>
    </form>
</body>
</html>
0
Comment
Question by:assaultkitty
  • 3
  • 2
5 Comments
 
LVL 38

Expert Comment

by:Tom Beck
ID: 37734084
The only problem I see in in your results alert. The syntax is wrong and there are two variables called error. It should be more like this:

                string hours = Convert.ToDouble(Text1.Value);
                string rate = Convert.ToDouble(Text2.Value);
                string result = string.Format("Your Gross Pay is $ {0}", hours - 40 * rate * 1.5);
                string script = "alert('" +result + "')";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "myScript", script, true);

This would calculate not the Gross Pay, but the pay for overtime hours greater than 40 and at a rate that is 1.5 times the regular hourly rate.

To get the Gross Pay for hours worked at regular rate would be:

                string hours = Convert.ToDouble(Text1.Value);
                string rate = Convert.ToDouble(Text2.Value);
                string result = string.Format("Your Gross Pay is $ {0}", hours  * rate );
                string script = "alert('" + result + "')";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "myScript", script, true);
0
 

Author Comment

by:assaultkitty
ID: 37734098
I am missing the argument and conditions for the new if else statement.  Also, I got this error message.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication4._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
 <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                alertOnDefaultPage();
            }
        }
        void alertOnDefaultPage()
        {
            string error, script = "";
            double dOutput = 0;
            string Text1_qs = Request.QueryString["Text1"];
            string Text2_qs = Request.QueryString["Text2"];
            if (Text1_qs.Length < 1)
            {
                error = "Please Enter a value in Hours Field ";
                script = "alert(\"" + error + "\");";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "myScript", script, true);

            }
            else if (!Double.TryParse(Text1_qs, out dOutput))
            {
                error = "Please Enter Valid Numbers in Hours Field ";
                script = "alert(\"" + error + "\");";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "myScript", script, true);
            }
            else if (Text2_qs.Length < 1)
            {
                error = "Please Enter a value in Pay Rate Field";
                script = "alert(\"" + error + "\");";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "myScript", script, true);

            }

            else if (!Double.TryParse(Text2_qs, out dOutput))
            {
                error = "Please Enter Valid Numbers in rate Field ";
                script = "alert(\"" + error + "\");";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "myScript", script, true);
            }

            else
            {
                double hours = Convert.ToDouble(Text1_qs);
                double rate = Convert.ToDouble(Text2_qs);
                script = "alert(\"" + String.Format("Your Gross Pay is $ {0}", hours - 40 * rate * 1.5) + "\");";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "myScript", script, true);
            }
        }
    </script>
       
</body>
</html>
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 37734104
I am monitoring your other question, C#9, and it is making me very confused. @meeran03 is under the impression that you are trying to get one form to submit to another form for the calculation. My understanding all along has been that you are working with just one form, Default.aspx and you were submitting it back to itself for the calculation. My solutions have been to that end. The code you pasted above is @meeran03 code, not mine.

You have too many questions open on this topic.

Please clarify your requirements. One form or two forms?
0
 

Author Comment

by:assaultkitty
ID: 37734487
This is the requirement.

This is the source.
ASP.NET Programming with C# and SQL Server by Don Gosselin page 187.
In my opinion, this is a terrible book for this problem.  There are no examples to this problem.

Create a program that calculate an employee's weekly gross salary, based on the number of hours worked and an hourly wage that you choose.  Use an HTML document containing a form with two text boxes-one for the number of hours worked and other for the hourly wage.  Submit the form to the Default.aspx file.  Calculate the pay in a function that returns a string containing the amount to the calling statement, which prints the string.  Compute any hours over 40 as time and a half.  Use the appropriate decision structure to create the program.  Save the project as Paycheck.  

From the my understanding that I need two forms one html and one default.aspx.  Can you help me If I am wrong?
0
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 37734776
In that case I think we are both steering you in the wrong direction. The html form should be simple with javascript to validate the form fields and javascript redirect to the Default.aspx page to display the result. What @meeran03 is doing is putting server side code on the html page and that makes it an aspx form, not a simple html form. But since @meeran03 is closer to the correct solution than I, I will leave him to it. To further complicate things, you have made me aware that this is a student assignment from the beginning. EE rules do not allow me to provide you with complete code for you to cut and paste. I can only provide guidence which I have attempted to do. I do not believe @meeran03 is aware of the fact that this is a student assignment so he is providing complete code.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

21 Experts available now in Live!

Get 1:1 Help Now