0

I seem to be having a problem with my button's OnClick, it doesn't even react at all to the event. It responds to OnClientClick and executes the code, but when I try to relate it o a function in my .aspx.cs class it just ignores it, and it should be executing very simple code (writing to the output debug)

I've checked every other stackoverflow post about this I could find and no one had the same issue.

I know that my Index.aspx is executing the code inside Index.aspx.cs because the Page_Load function is outputting to the debug window, so that's not the problem.

Here's the important code:

    <asp:Button ID="btnCreateOrder" runat="server" Text="Create Order" OnClick="btnClick" />

    protected void btnClick(object sender, EventArgs e)
    {

        System.Diagnostics.Debug.Write("Testing3");

    }

Like I said the Page_Load function is working fine so it's not an issue of them not being connected.

DIFFERENT PROBLEM IF YOU FEEL SO INCLINED:

While you're reading, I also have a problem of not being able to find objects from my HTML in my CS file.

What I mean by that is, if I reference this label:

    <asp:Label ID="testLabel" runat="server" Text="test"></asp:Label>

by saying

    testLabel = "Test2";

I get the error "The name 'testLabel does not exist in the current context"

And if I try to reference it by saying this:

    Index.testLabel = "Test2";

I get "'MyProject.Views.Home.Index' does not contain a definition for 'testLabel'" even though it clearly does.

halfer
  • 19,824
  • 17
  • 99
  • 186
noneabove
  • 89
  • 2
  • 12

1 Answers1

1

Maybe the .designer file is bad.

Try this: delete the .designer.cs file of your .aspx page, right-click on it and select the 'Convert to web application' option.

EDIT: As for the Button event, how did you generate the method stub for the click event? Did you click the button on the designer view twice and the visual studio generated id for you or did you handcoded it?

Try to delete both the button and the button click event, and when you declare the button again, double click it on the designer view.

Jvam
  • 238
  • 1
  • 13