Change asp:Button to asp:LinkButton

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
Does anyone know how to successfully change the asp:Button to asp:LinkButton without running into error. When I change it i receive this error: System.NullReferenceException: Object reference not set to an instance of an object..

I have changed it also in the .cs file to look for then as :LinkButton

Any thoughts would be appreciated. The reason I am doing this is because I want to be able to place HTML within the button it's self.

Thank you,
Brennan
13 years ago
I figured it out. If you're wanting to have an anchor tag be your button change the asp:Button to asp:LinkButton. In the .cs like look for where it is targeting that button in the databound functions.

change
e.Item.FindControl("btnAddToCart") as Button;
to
e.Item.FindControl("btnAddToCart") as LinkButton;

Then in the .ascx file change the CodeBehind to CodeFile. That should do it. Now if I understand correctly the Codefile pulls from the actual file and the CodeBehind call from the compiled application. I assume I would need to change it back to CodeBehind evetually but how on earth do you recompile the application? I have tried building it with VB, nothing. I have restarted the server, I have restarted the Application Pool and nothing did it.

If anyone has suggestions or comments please post.
13 years ago
You are spot on with your explanation of code-files and code-behind.  Because code-behind is compiled you can't just drop one in a existing application.  It won't work.  Just use the code-file if recompiling is not an option.  The performance will be negligible.
13 years ago
So how exactly do I recompile the application to include/update the .cs files? I am using Microsoft Visual Web Developer Express and it has the option to "Build Web Site" but not an option to recompile solution or rebuild it. Doing the "Build Web Site" doesn't really do anything that I can see. Would I need to use Visual Studio to accomplish a recompile or is there a better way?

Thanks
13 years ago
The option to build is under the build menu.  If you don't have the source version of nopCommerce then I don't think adding a new file will build because the version you most likely have is already precompiled.

Download the source version if you want to add custom items to the build.
13 years ago
Thank you Trevor, I found that out from some one else and I felt like a retard. Thanks for the reply though I'm sure it will be useful for the many other people who made the same mistake as I.
13 years ago
I think we all have worn the dunce cap now and again.  Glad you got it working.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.