Reputation: 825
I am a humble student on a work placement, and I have inherited a 'semi-finished' app. It is written in C#(no experience at all) .NET(a little experience), using AJAX(no experience) and Jquery(little experience). I wrote a little method to grab text from a webpage and parse it into a text document. I want it to fire when the user pushes 'publish'.
The button won't fire. I have put a breakpoint in my 'btnPublish_Click' handler, and it doesn't even reach it.
I've registered the button click event (I read that you needed to do this in C#):
namespace MaintainTenderFiles.ajax
{
public partial class publish : TendersPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
loadPendingTenders();
preloadTender();
btnPublish.Click += new EventHandler(this.btnPublish_Click);
}
else
{
//more code
Then coded the click event:
public void btnPublish_Click(object sender, EventArgs e)
{
String script = "alert('Clicked!!!');";
ScriptManager.RegisterStartupScript(this.Page, this.GetType(),
"alertScript", script, true);
}
All that happens when I click the button is it takes me to a page called 'published'.
Why can't I get the event to fire?
EDIT**
Apparently forgot to include the code for the button from the markup page:
<asp:Button ID="btnPublish" OnClick="btnPublish_Click"
CssClass="ui-state-default ui-corner-all" runat="server"
Text="Publish" CausesValidation="False" UseSubmitBehavior="False" />
Upvotes: 0
Views: 2122
Reputation: 740
Move the button event register so it registers every load.
namespace MaintainTenderFiles.ajax
{
public partial class publish : TendersPage
{
protected void Page_Load(object sender, EventArgs e)
{
btnPublish.Click += new EventHandler(this.btnPublish_Click);
if (Page.IsPostBack == false)
{
loadPendingTenders();
preloadTender();
}
else
{
Upvotes: 1