Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Button Event Handler scope (private vs public) ?
Message
De
31/08/2005 15:30:15
 
 
À
30/08/2005 11:38:34
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 1.1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01045181
Message ID:
01045650
Vues:
19
>ASP.NET v1.1 (VS.Studio 2003)
>
>I add a LinkButton named "lnkExport" and double-click on it.
>A method gets created automagically with the following signature:
>
>private void lnkExport_Click(object sender, System.EventArgs e)
>{
>}
>
>and this gets added to InitializeComponent()
>
>this.lnkExport.Click += new System.EventHandler(this.lnkExport_Click);
>
>
>All very nice. I add a Response.Write("Clicked") in lnkExport_Click() to see it working and run the page.
>I get a runtime error that object is inaccessible due to its protection level. I then make lnkExport_Click() public and it works.
>
>Why? Why does it need to be public when it is in the same page? All it does is it runs the code as a PostBack AFAIK.
>I fail to see why the auto-created private signature does not work.



More on this. left the issue for a couple of days, just commenting out the LinkButton so I could finish most of the app's functionality. All queries and display of results is done. Now I come bak to the button issue. After mucgh testing and reading of examples online I see that 'seem to be doing everything by the book, yet it does not work as advertised

I'm getting close to the deadline and this issue is the one stopping me.

To recap a little, this is what I do (simplified):
- user gets to the page and picks a report to see (from a dropdown)
- user picks a month/year for the report
- LinkButton is not visible at this point
- user presses SUBMIT button

There is only one page (default.aspx)
- The previous stuff runs in if (!PostBack)
- The SUBMIT resends to the same page into the PostBack section
- A class is instantiated, queries are built and run, a table is built (HTML table by hand as we need more control than a grid can do)
- LinkButton.Visible = true;
- Display of HTML Report works fine.
- User presses LinkButton ("Export Data")

now this is what happens and it is wrong:
- instead of LinkButton_Click() triggering, the run goes to PostBack again and this time it crashes on the first Request.Form() saying the form object is not found

I put a Response.Write/Response.End in the Button_Click() and it didn't trigger
I put a Response.Write/Response.End in InitializeComponent() and it didn't trigger, so it seems this is why the button is not triggering as this code:
this.lnkExport.Click += new System.EventHandler(this.lnkExport_Click);
is not seen.

Also, as mentioned before:
private void lnkExport_Click(object sender, System.EventArgs e) {}
gives a protection error. I need to make it public to avoid compiler error.

These behaviors do not make sense. Any ideas?


Alex Feldstein, MCP, Microsoft MVP
VFP Tips: English - Spanish
Website - Blog - Photo Gallery


"Once again, we come to the Holiday Season, a deeply religious time that each of us observes, in his own way, by going to the mall of his choice." -- Dave Barry
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform