• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

C#8

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
assaultkitty
Asked:
assaultkitty
  • 3
  • 2
1 Solution
 
Tom BeckCommented:
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
 
assaultkittyAuthor Commented:
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
 
Tom BeckCommented:
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
 
assaultkittyAuthor Commented:
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
 
Tom BeckCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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