Solved

C#

Posted on 2012-03-17
3
254 Views
Last Modified: 2012-03-17
Dear Sirs:  I am working on this C# program.  The form script will not compile for me.  Can you help me with this issue?

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Paycheck._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">
    <script  runat="server">
Sub Button_Click( s As Object, e As EventArgs )
   button1.Text="You clicked me!"
   End Sub
</script>

    <title>Pay Check</title>
    <link rel="stylesheet" href="asp_styles.css"
    type="text/css" />
</head>
<body>
    <form id="Form1" runat="server">
<asp:Button id="button1" Text="Click me!" runat="server" OnClick="submit" />
</form>
  </body>
</html>
0
Comment
Question by:assaultkitty
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 37732593
You are working on a C# program but you are putting VB code in the head section of the aspx page. If that is the handler for the button on the page then it would need to be in C# code and outside of the aspx markup. Also, remove the codebehind attribute in the Page directive if you intend on putting your code directly on the aspx page.

<%@ Page Language="C#" AutoEventWireup="true" Inherits="Paycheck._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    protected void submit(object sender, EventArgs e)
    {

    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
        <title>Pay Check</title>
    <link rel="stylesheet" href="asp_styles.css"
    type="text/css" />
</head>
<body>
    <form id="Form1" runat="server">
<asp:Button id="button1" Text="Click me!" runat="server" OnClick="submit" />
</form>
  </body>
</html>
0
 

Author Comment

by:assaultkitty
ID: 37733230
This is the form I have come up with.  Create a program that calculates an employee weekly gross salary based on the number of hours worked and an hourly wage that you choose.  This is my HTML document containing two text boxes and a submit box.  I have to submit the form to the Default.aspx file.  If this is correct, where do I go from here?
1. create a class paycheck that does the calculations.
or
2. Default.aspx

<!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>Pay Check</title>
 </head>
<body>

    <p><strong>Insert Hours Worked: </strong>
        <input id="Text1" type="text" onclick="return Text1_onclick()" /></p>
    <p><strong>Insert Pay Rate: </strong>
        <input id="Text2" type="text" onclick="return Text2_onclick()" /></p>
    <p>
        <input id="Submit1" type="submit" value="Calculate" onclick="return Submit1_onclick()" /></p>

</body>
</html>
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 37733376
Is this "create a class paycheck that does the calculations" a requirement of the assignment? Because it is not necessary to create a separate class to do the calculation. You could just submit the page to itself, do the calculation in code behind and return the result.

1. You need a way to display the result to the user. The easiest way is to add an asp:Label and assign the result to that.

2. Nothing will be submitted to the server on your form because you do not have form tags. For asp.net forms, the form tags must have the runat="server" attribute.

3. In order to be able to access the input controls in the form from the server, they need to be either asp.net controls or standard html controls (like you have) but with runat="server" attributes. Example: <asp:TextBox runat="server" ID="Text1"></asp:TextBox> OR <input type="text" id="Text1" runat="server" />. The same holds true for the Calculate button. It should be an asp:Button control or an input with a runat="server" attribute.

4. You have onclick attributes in each of your controls. Why do you need something to happen when the user clicks on your textbox? You only want to submit the form when the user clicks the button.

The form must be setup correctly before you can proceed to the server side calculation. You can post your updated form again if you have any more questions.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Class object 2 28
Syntax Error 2 48
How to have a gridview column with multiple items in a column row. 2 16
Issues with Insert statement 12 16
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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

24 Experts available now in Live!

Get 1:1 Help Now