3 Replies - 3900 Views - Last Post: 19 September 2011 - 08:02 AM Rate Topic: -----

#1 Goff256  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 93
  • Joined: 04-July 11

Compilation Error

Posted 18 September 2011 - 02:05 PM

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_1104C_IT_274__Michael_Goff__Unit_4._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>New User Information</title>
</head>
<body>
    <form id="form1" runat="server">
    >
<table>
  <tr>
    <td>
        Name:</td>
    <td><input type="text" runat="server" id="txtName"/></td>
  </tr>
    <tr>
    <td>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
            ControlToValidate="txtEmail"
            ErrorMessage="Email is required."> *
        </asp:RequiredFieldValidator>
    </td>
    <td>
    <p>
        &nbsp;</p>
    Email:</td>
    <td><input type="text" runat="server" id="txtEmail"/></td>
  </tr>
    <tr>
    <td>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
            ControlToValidate="txtUser"
            ErrorMessage="User ID is required."> *
        </asp:RequiredFieldValidator>
    </td>
    <td>
    <p>
        &nbsp;</p>
    User Name:</td>
    <td><input type="text" runat="server" id="txtUser"/></td>
  </tr>
    <tr>
    <td>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
            ControlToValidate="txtPassword"
            ErrorMessage="Password is required."> *
        </asp:RequiredFieldValidator>
    </td>
    <td>
    <p>
        &nbsp;</p>
    Password:</td>
    <td><input type="text" runat="server" id="txtPassword"/></td>
  </tr>
    <tr>
    <td>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
            ControlToValidate="txtConfirm"
            ErrorMessage="Password is required."> *
        </asp:RequiredFieldValidator>
    </td>
    <td>
    <p>
        &nbsp;</p>
    Confirm Password:</td>
    <td><input type="text" runat="server" id="txtConfirm"/></td>
  </tr>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" 
            onclick="btnSubmit_Click" />
</table>
    <asp:Label ID="lblCheck" runat="server" Text="Label"></asp:Label>
    <br/>
<input type="submit" runat="server" id="cmdSubmit" value="Submit" onserverclick="onsubmit"/>
    </form>
</body>
</html>



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _1104C_IT_274__Michael_Goff__Unit_4
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string confirm = txtConfirm.Value;
            string password = txtPassword.Value;

            if (confirm == password)
            {
                lblCheck.Text = "";
            }
            else
            {
                lblCheck.Text = "These passwords do not match";
            }


        }
    }
}


Quote

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1061: 'ASP.default_aspx' does not contain a definition for 'onsubmit' and no extension method 'onsubmit' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?)

Source Error:



Line 72: <asp:Label ID="lblCheck" runat="server" Text="Label"></asp:Label>
Line 73: <br/>
Line 74: <input type="submit" runat="server" id="cmdSubmit" value="Submit" onserverclick="onsubmit"/>
Line 75: </form>
Line 76: </body>


Source File: c:\Users\Michael\Desktop\1104C_IT 274_ Michael Goff_ Unit 4\1104C_IT 274_ Michael Goff_ Unit 4\Default.aspx Line: 74





This is my first time doing this, I have no clue how to solve this egregious error.

Is This A Good Question/Topic? 0
  • +

Replies To: Compilation Error

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4337
  • View blog
  • Posts: 12,137
  • Joined: 18-April 07

Re: Compilation Error

Posted 18 September 2011 - 03:58 PM

Your control for the submit button has the attribute 'onserverclick="onsubmit"'. This is saying that you have code that responds to the server click event and it is called "onsubmit". You don't have any function defined called "onsubmit".

First of all, you don't really need "onserverclick" there.. you just need "onclick" and secondly you need to define a click function just like you did for your other button btnSubmit.

So to fix this, go into the HTML source and delete the onserverclick="onsubmit" part. Then go into design view and double click your submit button. This should generate the proper click event for you and attach it to your submit button.

You will see something like onclick="cmdSubmit_Click" get added to the button instead. Remember, each event tied to a control has to be defined in the C# code. Look at your btnSubmit button code, that one is done properly.

:)
Was This Post Helpful? 2
  • +
  • -

#3 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 444
  • View blog
  • Posts: 1,492
  • Joined: 28-April 09

Re: Compilation Error

Posted 18 September 2011 - 09:16 PM

You should really be using the asp.net server controls rather than the standard html controls for the input boxes and the buttons. For instance, instead of using <input type='text' ... /> you could use the asp.net server control <asp:TextBox ID="textbox1" runat="server" Text=""></asp:TextBox>
Was This Post Helpful? 1
  • +
  • -

#4 Goff256  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 93
  • Joined: 04-July 11

Re: Compilation Error

Posted 19 September 2011 - 08:02 AM

View PostMartyr2, on 18 September 2011 - 03:58 PM, said:

Your control for the submit button has the attribute 'onserverclick="onsubmit"'. This is saying that you have code that responds to the server click event and it is called "onsubmit". You don't have any function defined called "onsubmit".

First of all, you don't really need "onserverclick" there.. you just need "onclick" and secondly you need to define a click function just like you did for your other button btnSubmit.

So to fix this, go into the HTML source and delete the onserverclick="onsubmit" part. Then go into design view and double click your submit button. This should generate the proper click event for you and attach it to your submit button.

You will see something like onclick="cmdSubmit_Click" get added to the button instead. Remember, each event tied to a control has to be defined in the C# code. Look at your btnSubmit button code, that one is done properly.

:)



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_1104C_IT_274__Michael_Goff__Unit_4._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 id="Head1" runat="server">
    <title>New User Information</title>
    <script language="javascript" type="text/javascript">
// <![CDATA[

        function cmdSubmit_onclick() {
        string confirm;
        confirm = txtConfirm.Value;
        string password;
        password = txtPassword.Value;

            if (confirm == password)
            {
                lblCheck.Text = "";
            }
            else
            {
                lblCheck.Text = "These passwords do not match";
            }

        }

// ]]>
    </script>
</head>
<body>
    <form id="form1" runat="server">
    >
<table>
  <tr>
    <td>
        Name:</td>
    <td><input type="text" runat="server" id="txtName"/></td>
  </tr>
    <tr>
    <td>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
            ControlToValidate="txtEmail"
            ErrorMessage="Email is required."> *
        </asp:RequiredFieldValidator>
    </td>
    <td>
    <p>
        &nbsp;</p>
    Email:</td>
    <td><input type="text" runat="server" id="txtEmail"/></td>
  </tr>
    <tr>
    <td>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
            ControlToValidate="txtUser"
            ErrorMessage="User ID is required."> *
        </asp:RequiredFieldValidator>
    </td>
    <td>
    <p>
        &nbsp;</p>
    User Name:</td>
    <td><input type="text" runat="server" id="txtUser"/></td>
  </tr>
    <tr>
    <td>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
            ControlToValidate="txtPassword"
            ErrorMessage="Password is required."> *
        </asp:RequiredFieldValidator>
    </td>
    <td>
    <p>
        &nbsp;</p>
    Password:</td>
    <td><input type="text" runat="server" id="txtPassword"/></td>
  </tr>
    <tr>
    <td>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
            ControlToValidate="txtConfirm"
            ErrorMessage="Password is required."> *
        </asp:RequiredFieldValidator>
    </td>
    <td>
    <p>
        &nbsp;</p>
    Confirm Password:</td>
    <td><input type="text" runat="server" id="txtConfirm"/></td>
  </tr>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" 
            onclick="btnSubmit_Click" />
</table>
    <asp:Label ID="lblCheck" runat="server" Text="Label"></asp:Label>
    <br/>
<input type="submit" runat="server" id="cmdSubmit" value="Submit" onclick="return cmdSubmit_onclick()" />
    </form>
</body>
</html>


Something like that?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1