1

When I run the application works on Visual Studio it works perfectly but when I upload it on the server I get an error of

The base class includes the field 'hiddenButton', but its type(System.Web.UI.WebControls.Button) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlButton).

For Button I Used:

<button id="hiddenButton" runat="server" onserverclick="btnClick_Click" style="display:none;" ></button>

C# code is:

   protected void btnClick_Click(object sender, EventArgs e)
    {

        DownloadAsPDF();
    }

    public void DownloadAsPDF()
    { 
Naive
  • 345
  • 2
  • 6
  • 18

2 Answers2

0

I changed some ASP buttons to HTML buttons:

From <asp:Button ID="btnAdd" runat="server" UseSubmitBehavior="false" Text="Add" />

To <button ID="btnAdd" runat="server" type="button">Add</button>

This caused the same error you received. The solution was to add the directive using System.Web.UI.HtmlControls; to my code behind (.cs) file.

Apparently changing the ID to something different than the original control would have tipped off the compiler, but I'm not certain about that and didn't want to change my ID, compile everything and then change the ID back to what I originally wanted.

Having said that, changing the ID did get the squiggly error indicator to go away. But in the end I just manually inserted the directive into the code behind and it worked out. Props to this article that provided the insight.

Kevin Scharnhorst
  • 721
  • 1
  • 7
  • 14
0

I had to clean my solution for the warning to go away. Build Menu -> Clean Solution.

It happened because I changed the to while IIS Express was still running.

Michael
  • 2,825
  • 3
  • 24
  • 30