Solved

C#8

Posted on 2012-03-17
5
229 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

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

Suggested Solutions

Title # Comments Views Activity
Google Directions API to Map URL -C#? 3 37
Asp in script 6 37
ASP Repeater control - onl;y show if flag is true 7 15
JQuery Autocomplete Tag AJAX (Need nice script) 11 34
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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