Solved

C#4

Posted on 2012-03-17
15
267 Views
Last Modified: 2012-03-18
This is the error that I am getting in the program can you help and guide me in the right direction?

SCRIPT5009: 'Text2_onclick' is undefined
HTMLPa<!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" >
         function Text1_onclick() {
         }
        function Text2_onclick() {

         }
        void Submit1_onclick(object sender, EventArgs e) {
             if (Text1.Value.Length < 1)
             {
                Response.Write("Please Enter a value in Hours Field ");
              }
            else if(Text2.Value.Length < 1)
             {
                MessageBox.Show("Please Enter a value in Pay Rate Field");
              }
            else
             {
                double hours = Convert.ToDouble(textBox1.Text);
                double rate = Convert.ToDouble(textBox2.Text);
                MessageBox.Show(string.Format("Your Gross Pay is $ {0}" ,hours - 40 * rate * 1.5));
             }
       </script>
    <form action="Default.aspx" method="post">
    <p>Enter Hours Worked:<input id="Text1" type="text" onclick="return Text1_onclick()" /></p>
    <p>Enter Pay Rate:<input id="Text2" type="text" onclick="return Text2_onclick()" /></p>
    <p><input id="Submit1" type="submit" value="submit" onServerClick="Submit1_onclick" /></p>
    </form>
</body>

</html>
0
Comment
Question by:assaultkitty
  • 9
  • 6
15 Comments
 
LVL 7

Accepted Solution

by:
markmiddlemist earned 500 total points
ID: 37733733
The problem you've got is that the functions you are defining are server-side, and so are not rendered to the web browser. I'm assuming here that what you want is to execute the code in the functions on the client. Unfortunately C# cannot be used to write client script, so you will need to remove the runat="server" attribute from the script tag and create javascript functions in there.

There are many many introductory books, webcasts, etc out there on asp.net which should help you undersant this distinction and how to make the framework work for you- have a look at http://www.asp.net/ for a start
0
 

Author Comment

by:assaultkitty
ID: 37733915
Mark how would I do this?  I was told by an expert that this the proper way?  Help!
0
 
LVL 7

Expert Comment

by:markmiddlemist
ID: 37733921
OK, I'll help as much as possible. What is it you are trying to actually do?
0
 

Author Comment

by:assaultkitty
ID: 37733931
I am having problems getting the html page to produce the input.  I am assuming that the page is waiting for the default.aspx to be constructed by me.  Therefore, I am going to work on that.  I do not understand why the script should not be runat.  I looked in the book and it says to use the runat.  Can you clarify?
0
 

Author Comment

by:assaultkitty
ID: 37733938
As, I can I have a clear example of how the Default page should look?
0
 

Author Comment

by:assaultkitty
ID: 37733990
i am learning thank you!
0
 
LVL 7

Expert Comment

by:markmiddlemist
ID: 37734492
Cool. I often recommend at least going through the training for the appropriate Microsoft certifications as a good way to generally upskill. In this case have a look at 70-515 : Web Application development in .net 4 (http://www.microsoft.com/learning/en/us/exam.aspx?ID=70-515) 0 The self paced training kits are excellent. It won't give you a dep dep knowledge, but gives you a good general overview of what tools and techniques you have available to you as a developer, and how to use them.

Are you OK to move on with this yourself, or do you need help still? I'll be online for a fair bit of today so feel free to reply if you do need assistance.

All the best

Mark (@delradie - http://delradiesdev.blogspot.com/)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:assaultkitty
ID: 37734505
I still need help.  I am a little confused.  I will book mark this reference and use it. I will be at the computer all day.  I have to turn in my project tonight at 12 AM.
0
 
LVL 7

Expert Comment

by:markmiddlemist
ID: 37734547
OK, what actually is the brief for this (I'm obviously not going to do the work for you if its for an assigment, but I can point you at the appropriate techniques best with this info)?
0
 

Author Comment

by:assaultkitty
ID: 37734570
This is what I have so far.  I made a mistake on this submission.  I am including a link to the amazon to the book that I am using.  Can you give some ideas to what will help me arrive at my solution.  

This is my reference can you help me?

http://www.amazon.com/ASP-NET-Programming-Server-Technologies/dp/1423903242/ref=sr_1_1?ie=UTF8&qid=1332070105&sr=8-1


<!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
 
LVL 7

Expert Comment

by:markmiddlemist
ID: 37734942
OK, this is actually a way of doing things I'm not familiar with, but rather than confusing you be introducting asp server controls etc, I've just done a quick readup

It looks like there are 2 things (possibly) wrong:

1 - this may not actually be an issue but in the <script runat="server"> you might need to specify the actual language you are using:

<script runat="server" language="C#">

2 - the onserverclick event you are tapping in to is probably only available on the html button, what happens if you remove the onServerClick="TextX_onClick" from the two textboxes?
0
 

Author Comment

by:assaultkitty
ID: 37735142
I am sorry about the break.  I had to write a five page report to turn in to night. I am ready to devote all of my attention to this project.
0
 

Author Comment

by:assaultkitty
ID: 37735169
Step one that you suggested worked but step two brought up a text box. when I clicked the text box.  It is a gray dialog box. Can you help me?

One good thing is that I do not see the compilation errors any more.  I see the HTML page.  I can enter information but once I click the submit button the numbers disappear and the page does not go to the local host.
0
 
LVL 7

Expert Comment

by:markmiddlemist
ID: 37735468
This is probably down to the action="Default.aspx"  in your form tag - this is telling your form to post to. In order to run your code it actually needs to post to itself, which is the default action so remove that and try again.
0
 

Author Comment

by:assaultkitty
ID: 37735885
Meena06 help me and that is what I currently have for the default.aspx.  I do not see the Default.aspx in the file.  One of the Experts proved to me that this program is working.  So, I am going with it but I am still having problems with getting it to load to my local host.  I think I need some help configuring my IDE.  Can you help me with this issue?  I really need to see what the program looks like for myself.  I am going to post for some help setting up my IDE.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

23 Experts available now in Live!

Get 1:1 Help Now