473,770 Members | 3,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Web User Control Event prob.

I have a class that inherits from System.Web.Ui.U sercontrol... all is
basically is is a button which is created progammatically such as:

public abstract class BaseFrontEndEdi tor : System.Web.UI.U serControl
{
protected Button btnEdit = new Button();

private void Page_Load(objec t sender, System.EventArg s e)
{

if( ! this.IsPostBack )
{
btnEdit.Text="E dit";
btnEdit.ID = "btnEdit";
this.btnEdit.Cl ick += new System.EventHan dler(this.btnEd it_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
"initializeComp onent", 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
Nov 18 '05 #1
3 1666
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******** ******@tk2msftn gp13.phx.gbl...
I have a class that inherits from System.Web.Ui.U sercontrol... all is
basically is is a button which is created progammatically such as:

public abstract class BaseFrontEndEdi tor : System.Web.UI.U serControl
{
protected Button btnEdit = new Button();

private void Page_Load(objec t sender, System.EventArg s e)
{

if( ! this.IsPostBack )
{
btnEdit.Text="E dit";
btnEdit.ID = "btnEdit";
this.btnEdit.Cl ick += new System.EventHan dler(this.btnEd it_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
"initializeComp onent", 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

Nov 18 '05 #2
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******** ******@TK2MSFTN GP11.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******** ******@tk2msftn gp13.phx.gbl...
I have a class that inherits from System.Web.Ui.U sercontrol... all is
basically is is a button which is created progammatically such as:

public abstract class BaseFrontEndEdi tor : System.Web.UI.U serControl
{
protected Button btnEdit = new Button();

private void Page_Load(objec t sender, System.EventArg s e)
{

if( ! this.IsPostBack )
{
btnEdit.Text="E dit";
btnEdit.ID = "btnEdit";
this.btnEdit.Cl ick += new System.EventHan dler(this.btnEd it_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 "initializeComp onent", 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


Nov 18 '05 #3
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******** ********@TK2MSF TNGP12.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******** ******@TK2MSFTN GP11.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******** ******@tk2msftn gp13.phx.gbl...
I have a class that inherits from System.Web.Ui.U sercontrol... all is
basically is is a button which is created progammatically such as:

public abstract class BaseFrontEndEdi tor : System.Web.UI.U serControl
{
protected Button btnEdit = new Button();

private void Page_Load(objec t sender, System.EventArg s e)
{

if( ! this.IsPostBack )
{
btnEdit.Text="E dit";
btnEdit.ID = "btnEdit";
this.btnEdit.Cl ick += new System.EventHan dler(this.btnEd it_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 "initializeComp onent", 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



Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1356
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 properties of this is held in one custon Class. By setting TypeConverter attribute to the above class we could make it the subproperty. AS a singale control its working fine. Now, We have created another User Control, InfoMultiLabel, that uses this...
4
4291
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 I know I need to call a function that will save data but I'm not sure exactly when to call this function. I've tried two ways and both seem to have 'gotcha's':
3
2563
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 details, their locations, and then add themselves to categories. Each category requires additional info from the suppliers, this additional category info is stored in its own DB table. a suppliers may add themselves to as many categories as required....
1
7587
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 dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
5
9751
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 this user control inside another webform. The webform has a "Next" button which is initially disabled. When the user control successfully adds a record I want the Next button on the webform to get enabled. Checking if the record was added...
6
3380
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 the usual stuff of recreating the usercontrol in the Page Init event. The 'failure' sequence is as follows: - select web form button to display the user control - select user control button, event fires - select web form button to display...
4
1754
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 specific process is done,, but the form which will host the user control has to specify what has to be done Something like this , if the event is fired it should call the event in
13
6232
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? I'm basically trying to set it up so that I can keep the User infor (userid, ect) in the Masterpage so that other pages can access it. Thanks for any ideas. Michael
5
2165
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) txtAddress.Text = value End Set
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10237
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7431
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.