I have a class that inherits from System.Web.Ui.Usercontrol... all is
basically is is a button which is created progammatically such as:
public abstract class BaseFrontEndEditor : System.Web.UI.UserControl
{
protected Button btnEdit = new Button();
private void Page_Load(object sender, System.EventArgs e)
{
if( ! this.IsPostBack )
{
btnEdit.Text="Edit";
btnEdit.ID = "btnEdit";
this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click);
}
}
The button is then added to the class's control collection.
I created another usercontrol that inherrits from this class, and placed it
on a page. This works, and when I view the aspx page the control is on, I
see the button. However, clicking the button never fires the event handler
("btnEdit_Click"). I have tried adding the event handler in the controls
"initializeComponent", as well as immediately after it is added (as seen
above). I have placed a simple Response.Write("hello") in the btnEdit_Click
function and nothing happens when the button is clicked. In fact, even the
button disappears. What's happening?
Thanks for any help!
-D 3 1644
You need to add the button every time the control loads - not just the first
time. I am guess you are checking the IsPostBack property and only doing it
the first time.
Please remember that HTTP is a stateless protocol. The page and all tis
contents are recreated every time there is a request. So if you only add
the button if the request is not a postback - after the button is clicked,
it is not created. And since it doesn't exist, there is no event to fire for
it.
"Big D" <a@a.com> wrote in message
news:uC**************@tk2msftngp13.phx.gbl... I have a class that inherits from System.Web.Ui.Usercontrol... all is basically is is a button which is created progammatically such as:
public abstract class BaseFrontEndEditor : System.Web.UI.UserControl { protected Button btnEdit = new Button();
private void Page_Load(object sender, System.EventArgs e) {
if( ! this.IsPostBack ) { btnEdit.Text="Edit"; btnEdit.ID = "btnEdit"; this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click); } }
The button is then added to the class's control collection.
I created another usercontrol that inherrits from this class, and placed
it on a page. This works, and when I view the aspx page the control is on, I see the button. However, clicking the button never fires the event
handler ("btnEdit_Click"). I have tried adding the event handler in the controls "initializeComponent", as well as immediately after it is added (as seen above). I have placed a simple Response.Write("hello") in the
btnEdit_Click function and nothing happens when the button is clicked. In fact, even
the button disappears. What's happening?
Thanks for any help!
-D
Thanks, however it's still not working. You were, of course, right about
the stateless nature, so it is no longer only being adding if not postback.
The button is now still there after postback, but it still does not fire the
event.
I've updated it a bit now, and it works as follows
onInit : The button is created and its handler is added. I am specifying a
unique id for the button, and the id is the same after postback.
onPreRender: The control is added to the page.
Clicking the button has no effect! Why is this?
-D
"Marina" <so*****@nospam.com> wrote in message
news:ei**************@TK2MSFTNGP11.phx.gbl... You need to add the button every time the control loads - not just the
first time. I am guess you are checking the IsPostBack property and only doing
it the first time.
Please remember that HTTP is a stateless protocol. The page and all tis contents are recreated every time there is a request. So if you only add the button if the request is not a postback - after the button is clicked, it is not created. And since it doesn't exist, there is no event to fire
for it.
"Big D" <a@a.com> wrote in message news:uC**************@tk2msftngp13.phx.gbl... I have a class that inherits from System.Web.Ui.Usercontrol... all is basically is is a button which is created progammatically such as:
public abstract class BaseFrontEndEditor : System.Web.UI.UserControl { protected Button btnEdit = new Button();
private void Page_Load(object sender, System.EventArgs e) {
if( ! this.IsPostBack ) { btnEdit.Text="Edit"; btnEdit.ID = "btnEdit"; this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click); } }
The button is then added to the class's control collection.
I created another usercontrol that inherrits from this class, and placed it on a page. This works, and when I view the aspx page the control is on,
I see the button. However, clicking the button never fires the event handler ("btnEdit_Click"). I have tried adding the event handler in the
controls "initializeComponent", as well as immediately after it is added (as seen above). I have placed a simple Response.Write("hello") in the btnEdit_Click function and nothing happens when the button is clicked. In fact, even the button disappears. What's happening?
Thanks for any help!
-D
On prerender is too late to add it to the page. The event handler would
have already fired by this point. So the second time the page loads - the
point at which the event would have fired is gone, and then you are just
adding the button to the page before the HTML is sent to the client.
You need to add the button to the page in page_init or page_load
"Big D" <a@a.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... Thanks, however it's still not working. You were, of course, right about the stateless nature, so it is no longer only being adding if not
postback. The button is now still there after postback, but it still does not fire
the event.
I've updated it a bit now, and it works as follows
onInit : The button is created and its handler is added. I am specifying
a unique id for the button, and the id is the same after postback.
onPreRender: The control is added to the page.
Clicking the button has no effect! Why is this?
-D "Marina" <so*****@nospam.com> wrote in message news:ei**************@TK2MSFTNGP11.phx.gbl... You need to add the button every time the control loads - not just the first time. I am guess you are checking the IsPostBack property and only doing it the first time.
Please remember that HTTP is a stateless protocol. The page and all tis contents are recreated every time there is a request. So if you only
add the button if the request is not a postback - after the button is
clicked, it is not created. And since it doesn't exist, there is no event to fire for it.
"Big D" <a@a.com> wrote in message news:uC**************@tk2msftngp13.phx.gbl... I have a class that inherits from System.Web.Ui.Usercontrol... all is basically is is a button which is created progammatically such as:
public abstract class BaseFrontEndEditor : System.Web.UI.UserControl { protected Button btnEdit = new Button();
private void Page_Load(object sender, System.EventArgs e) {
if( ! this.IsPostBack ) { btnEdit.Text="Edit"; btnEdit.ID = "btnEdit"; this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click); } }
The button is then added to the class's control collection.
I created another usercontrol that inherrits from this class, and
placed it on a page. This works, and when I view the aspx page the control is
on, I see the button. However, clicking the button never fires the event handler ("btnEdit_Click"). I have tried adding the event handler in the controls "initializeComponent", as well as immediately after it is added (as
seen above). I have placed a simple Response.Write("hello") in the btnEdit_Click function and nothing happens when the button is clicked. In fact,
even the button disappears. What's happening?
Thanks for any help!
-D
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mohandas P.M |
last post by:
Hi,
We have a prob with .Net User Controls, something like this. I have a
Custon Control InfoLabel Derived from System.Windows.Forms.Label ( Direct
Inheritance - Custom Control) and the some...
|
by: John |
last post by:
Hi all,
This really is quite an urgent matter.
I have a page with multiple, dynamically-loaded user controls and when a
user clicks on a button, the whole form is submitted. Now at this stage...
|
by: Tim Thomas |
last post by:
Hi,
I am very new to .NET and am in the process of building my first web
application.
I will briefly describe what i am trying to achieve:
I have a system where suppliers register their...
|
by: Shourie |
last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle.
1) MainPage_load
2) User control1_Load
user clicks a...
|
by: George Durzi |
last post by:
I have a simple user control with a text box and a submit button. When the
user enters some text into the textbox and clicks the submit button, a
record is created in the database.
I'm using...
|
by: Steve Booth |
last post by:
I have a web form with a button and a placeholder, the button adds a user
control to the placeholder (and removes any existing controls). The user
control contains a single button. I have done all...
|
by: thomson |
last post by:
Hi all,
i do have a user control with 4 buttons, and all the events
are firing properly,
My problem is that i need to right an event handler in the user
control, which gets fired after a...
|
by: Michael |
last post by:
I have setup a public variable in the Master Page "code-behind-file". Now I
would like to set that value from the UserControl, but I can't seem to find a
way to do this. Does anyone have any ideas?...
|
by: rn5a |
last post by:
Consider the following user control which resides in Address.ascx:
<script runat="server">
Public Property Address() As String
Get
Address = txtAddress.Text
End Get
Set(ByVal value As String)...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |