Solved

C#8

Posted on 2012-03-17
5
239 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
[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
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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