Reputation: 825
I have been tasked with completing an app that is 75% done. It has been created using three technologies I've never used (I am a student on a work term): asp.net, ajax, and it is written in C#.
One of the features of this app is html generation. I have written a method, we'll call it createHTML(). I have tested it as a standalone, and it works fine. I would now like to run it in the actual .net environment. When the user clicks the button btnCreate, the createHTML() method (which is being passed a NameValueCollection 'page') should grab a bunch of html and write it to a text file in a separate folder.
My question is: how do I do this? I have had some experience with VB .net, and normally what I would do there is go into design mode, double click on the btnCreate, and it would take me to the code view and I could code out a btnCreate_Click handler. However, the guy that wrote the original has all of the buttons hidden, and I can't figure out how to find them. I tried to manual write a btnCreate_Click call with just a messagebox popup, but can't get it to fire.
Compounding this issue, is that the original coder has written buttons throughout the app that are both asp:buttons, and regular HTML buttons. Should I be making this an asp button, or is it best to use html buttons? I understand the difference between using one for client side and the other for serverside, but when he's used both, what's best? And when using html, is that where the ajax comes in?
Apologies for the simplicity of this question, but it's driving me crazy.
EDIT:
Apparently, I have been too wordy. Here is how the button is coded:
<button id="createButton" class="ui-state-default ui-corner-all">Create</button>
Which is the original html button (again - in this case do I use AJAX)? Or should I do something like this:
<asp:Button ID="createButton" class="blah-blah-ui" PostBackUrl=".../somepage.aspx" runat="server" text="create" />?
If I do the asp button (which, at my level of AJAX - read:none - is probably best), how do I call the method that I have on a separate code behind page?
If my method is called showMessage() in 'modify.aspx.cs', how do I call this showMessage() method?
EDIT the second:
According to the answer I have received, I was on the right track. Problem is, onclick does not work. I found where the original coder hid all of the buttons, so I made them visible. In the properties window of my create button, OnClick is not even an option. The only option near that is OnClientClick, which I assume is for javascript?
Upvotes: 1
Views: 904
Reputation: 2344
I would say you should stick to using an asp:Button - just be aware this will cause the page to reload on each click, going the Ajax route avoids this but may be slightly harder to implement what you want.
You will need to wire up the code to handle the button click the easiest way is to use the OnClick attribute like this
<asp:Button ID="createButton" class="blah-blah-ui" runat="server" Text="create" OnClick="createButton_Click" />
And then in your code behind you handle the event like this
protected void createButton_Click(object sender, EventArgs e){}
Inside that handler you can then do whatever is is you want to do.
Upvotes: 1