SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Build your own ASP.NET - Take a survey

    Hello all,

    I've been going through the Build your own ASP.NET 4, and I have to say so far I am learning a good deal.
    However I have got stuck on chapter 4 when you have to make a survey. I followed the code exactly as it shows in the book but when ever I run it I get the following error:
    Code:
    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.survey_aspx' does not contain a definition for 'click' and no extension method 'click' accepting a first argument of type 'ASP.survey_aspx' could be found (are you missing a using directive or an assembly reference?)
    
    Source Error:
    
     
    
    Line 62:     <!-- Display confirmation button -->
    Line 63:     <p>
    Line 64:       <button id="confirmButton" OnServerClick="click" runat="server">Confirm</button>
    Line 65:     </p>
    Line 66:     <!-- confirmation label -->
    At first I thought I had done something silly so I downloaded the original code from the website and tried that but I still got the same error. I'm not sure what to do next so can anyone help me out?

    Thank you

  2. #2
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Show your code. Survey.aspx and Survey.aspx.cs

    Looks like you either misspelled protected void click(object sender, EventArgs e) or you forgot to put it in altogether. If you're using C# it is case-sensitive.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    servey.aspx
    PHP Code:
    <%@ Page Language="C#" %>

    <!
    DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 transitional //EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
    >

      <
    script runat="server">
          
    void Click(Object sEventArgs e)
          {
              
    feedbackLabel.Text "Your name is: " name.Value "<br />";
              
    feedbackLabel.Text += "Your email is: " email.Value +
                  
    "<br />";
              
    feedbackLabel.Text += "You like to work with:<br />";
              for (
    int i 0<= serverModel.Items.Count 1i++)
              {
                  if (
    serverModel.Items[i].Selected)
                  {
                      
    feedbackLabel.Text += " - " serverModel.Items[i].Text +
                          
    "<br />";
                  }
              }
              
    feedbackLabel.Text += "You like .NET: " likeDotNet.Value;
          }
      
    </script>

      <html xmlns= "http://www.w3.org/1999/xhtml">
        <head runat="server">
          <title>Using ASP.NET HTML Server Controls</title>
        </head>
        <body>
          <form id="form1" runat="server">
      <div>
        <h1>Take the survey!</h1>
        <!-- Display username -->
        <p>
         Name:<br />
         <input type="text" id="name" runat="server" />
        </p>
        <!-- Display email -->
        <p>
         Email:<br />
         <input type="text" id="email" runat="server" />
        </p>
        <!-- Display technology options -->
        <p>
         Which server technologies do you use?<br />
         <select id="serverModel" runat="server" multiple="true">
         <option>ASP>NET</option>
         <option>PHP</option>
         <option>JSP</option>
         <option>CGI</option>
         <option>ColdFusion</option>
         </select>
        </p>
        <!-- Display .NET preferences options -->
        <p>
         Do you like .NET so far<br />
         <select id="likeDotNet" runat="server">
           <option>Yes</option>
           <option>No</option>
         </select>
        </p>
        <!-- Display confirmation button -->
        <p>
          <button id="confirmButton" OnServerClick="click" runat="server">Confirm</button>
        </p>
        <!-- confirmation label -->
        <p>
          <asp:Label ID="feedbackLabel" runat="server" />
        </p>
      </div>
      </form>
      </body>
      </html> 

    survey.aspx.cs
    PHP Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public 
    partial class _Default System.Web.UI.Page
    {
        protected 
    void Page_Load(object senderEventArgs e)
        {

        }


  4. #4
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Hmm. So, where is the handler named "click" in survey.aspx.cs? It's not there, that's what the error is telling you, right?

    There should be something like this in there:
    PHP Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public 
    partial class _Default System.Web.UI.Page
    {
        protected 
    void Page_Load(object senderEventArgs e)
        {

        }
        protected 
    void click(object senderEventArgs e)
        {
            
    // handle click event here
        
    }

    [/QUOTE]

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the aspx.cs code is inside the .cs code, so the handler named click is inside the survey.cs file.
    This:
    Code:
    <script runat="server"> 
          void Click(Object s, EventArgs e) 
          { 
              feedbackLabel.Text = "Your name is: " + name.Value + "<br />"; 
              feedbackLabel.Text += "Your email is: " + email.Value + 
                  "<br />"; 
              feedbackLabel.Text += "You like to work with:<br />"; 
              for (int i = 0; i <= serverModel.Items.Count - 1; i++) 
              { 
                  if (serverModel.Items[i].Selected) 
                  { 
                      feedbackLabel.Text += " - " + serverModel.Items[i].Text + 
                          "<br />"; 
                  } 
              } 
              feedbackLabel.Text += "You like .NET: " + likeDotNet.Value; 
          } 
      </script>

  6. #6
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Oh, I'm sorry. I didn't see that. I knew you could do that but I've never actually seen it done in practice. I've always seen the code behind used.

    OK, now that I see what I should have seen, it is a case issue.
    Change this:
    Code Csharp:
    <button id="confirmButton" OnServerClick="click" runat="server">Confirm</button>
    to this:
    Code Csharp:
    <button id="confirmButton" OnServerClick="Click" runat="server">Confirm</button>

  7. #7
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HAHA Thanks so much, I went over that code so many times. I can't believe it was something so simple as that.

  8. #8
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vpa View Post
    HAHA Thanks so much, I went over that code so many times. I can't believe it was something so simple as that.
    Yeah, it happens. Sometimes an extra eye or two on the code can reveal the issue.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •