c# - aspx file does not contain a definition for function, definition in connected aspx.cs file -


answer given andrei (part solved me in comments on answer)

trying have onclick button, i'm getting

'asp.views_home_index_aspx' not contain definition 'btncreateorder_click' , no extension method 'btncreateorder_click' accepting first argument of type 'asp.views_home_index_aspx' found (are missing using directive or assembly reference?)

my code:

index.aspx:

<%@ page language="c#" masterpagefile="~/views/shared/site.master" inherits="system.web.mvc.viewpage" autoeventwireup="true" codebehind="index.aspx.cs" %> *there comment inherit near end of post* <asp:content id="content1" contentplaceholderid="titlecontent" runat="server">     home page </asp:content>  <asp:content id="content2" contentplaceholderid="maincontent" runat="server">     <h2><%: viewdata["message"] %></h2>     <table id="producttable">      </table>     <asp:label id="testmessage" runat="server" text="fail"></asp:label>     <p>         learn more asp.net mvc visit <a href="http://asp.net/mvc" title="asp.net mvc website">http://asp.net/mvc</a>.     </p>      <asp:button id="btncreateorder" runat="server" text="create order" onclick="btncreateorder_click" />  </asp:content> 

index.aspx.cs:

using system; using system.web; using system.web.ui; using system.collections.generic; using system.web.ui.webcontrols; using system.xml; using system.linq;  namespace myproject.views.home {     public partial class index : system.web.ui.page     {         protected void page_load(object sender, eventargs e)     {           system.diagnostics.debug.write("testing");         xmltextreader reader = new xmltextreader("data/products.xml");          while (reader.read())         {              system.diagnostics.debug.write(reader.name);          }           int numrows = 21;         int numcells = 4;         (int rownum = 0; rownum < numrows; rownum++)         {             tablecell cel = new tablecell();          }     }      public void btncreateorder_click(object sender, eventargs e)     {        system.diagnostics.debug.write("testing");     }  } 

on semi related note, can't page_load run on.. well, page load. (hence debug "testing") if know what's going wrong there that'd awesome :)

inheritance comment suggested change inheritance myproject.views.home.index need system.web.mvc.viewpage in order deal mvc layout, without : system.invalidoperationexception: view @ '~/views/home/index.aspx' must derive viewpage, viewpage, viewusercontrol, or viewusercontrol. so... yeah, unless i'm supposed put functions elsewhere in controllers file (i'm new visual studio) not sure :/

i've seen changing inheritance fix if set proper file directive breaks (proper myproject.views.home) returns "could not load type 'myproject.views.home'." not sure what's going on there. other that, yes they're in same folder , yes they're attached , it's set codebehind.

thanks in advanced!

ps if brackets wrong that's because screwed formatting, don't post here like, ever, sorry!

you have wrong value in page's inherits attribute. actual code-behind class should there:

inherits="myproject.views.home.index" 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -