views:

47

answers:

3

Given the form:

<form runat="server">
    **Omitted field data for simplicity**           
    <asp:Button runat="server" id="btn_addNewPrice" OnClick="newPrice_click" Text="Add New Price" />    
</form>

And the code behind:

// A new price has been entered
void newPrice_click(object sender, EventArgs e)
{
    // Get form values
    DateTime frm_datestart = DateTime.Parse(dateStart.Text);
    DateTime frm_dateend = DateTime.Parse(dateEnd.Text);
    double frm_percent = double.Parse(percentage.Text);
}

I get the error:

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

+2  A: 

If you put a breakpoint on your code, you can see if the code is hit (the breakpoint gets hit).

I think you should use an asp:button or implement the postback using the following tuterial: http://www.dotnetspider.com/resources/1521-How-call-Postback-from-Javascript.aspx

edit: What i always do, I select the button, go to properties and then on the events tab (lighting symbol) I select the event that I want to use for click, or i double click to make a new one.

Ivo
+1  A: 

Use:

protected void newPrice_click(object sender, EventArgs e)
{

}
Tom Gullen
A: 

Because you didn't specify an access modifier, your newPrice_click method defaults to Private. Try declaring it as Protected and see if that helps.

The way the page class is actually created is that a class is created from your .aspx file that inherits from the class in the .cs file. If the event handler method is private, it cannot be seen from the child class, aka the class from your .aspx file.

epotter