473,490 Members | 2,472 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Click event before on init

Hi,

I would need that when i click the button the code of the Onclick method
executes first, and then the onInit Method...

Its possible make this?
--
Thanks
Regards.
Josema
Nov 16 '05 #1
5 6769
Hi,

Is this a Web or a win app?

You should give more details.

I dont remember an OnInit method in a win app environment, so it should be
a web app.
In this case the OnInit is fired for the page, not for a button control in
the page.

If you are refering to a postback, you can't do nothing as the Page.OnInit
is fired before the control is even restored the status.

Again, what is your problem and we may provide you with a better solution.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Josema" <Je******@ocu.org> wrote in message
news:54**********************************@microsof t.com...
Hi,

I would need that when i click the button the code of the Onclick method
executes first, and then the onInit Method...

Its possible make this?
--
Thanks
Regards.
Josema

Nov 16 '05 #2


Mi problem is exactly this (in Web)
I have:

- an aspx page
- an ascx control (Exercise1.ascx)
- an ascx control (Exercise2.ascx)

Inside the aspx page i have a placeholder to add a control dinamically.
This placeholder's name is Exercise.

In the aspx page i have this in the OnInit:

override protected void OnInit(EventArgs e)
{
if(Page.Session["Exercise"]!=null)
{
switch(Page.Session["Exercise"].ToString())
{
case "Exercise2.ascx":
Exercise2 Exercise2_=(Exercise2)LoadControl("Exercise2.ascx" );
Exercise.Controls.Add(Exercise2_);
break;
}
}
else
{
Exercise1 Exercise1_=(Exercise1)LoadControl("Exercise1.ascx" );
Exercise.Controls.Add(Exercise1_);
}
}

In the (for instance) Exercise1.ascx i have this in the onClick method
of a button:

private void ExerciseBtn_Click(object sender, EventArgs e)
{
//add into the session the next exercise to load
Page.Session.Add("Exercise","Exercise2.ascx");
}
If i click in the button inside the usercontrol twice the program works,
but i would like only to need one click.
Thanks.
Josema.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Hi Ignacio, Mi problem is exactly this (in Web)
I have:
- an aspx page
- an ascx control (Exercise1.ascx)
- an ascx control (Exercise2.ascx)

Inside the aspx page i have a placeholder to add a control dinamically.
This placeholder's name is Exercise.

In the aspx page i have this in the OnInit:

override protected void OnInit(EventArgs e)
{
if(Page.Session["Exercise"]!=null)
{
switch(Page.Session["Exercise"].ToString())
{
case "Exercise2.ascx":
Exercise2 Exercise2_=(Exercise2)LoadControl("Exercise2.ascx" );
Exercise.Controls.Add(Exercise2_);
break;
}
}
else
{
Exercise1 Exercise1_=(Exercise1)LoadControl("Exercise1.ascx" );
Exercise.Controls.Add(Exercise1_);
}
}

In the (for instance) Exercise1.ascx i have this in the onClick method
of a button:

private void ExerciseBtn_Click(object sender, EventArgs e)
{
//add into the session the next exercise to load
Page.Session.Add("Exercise","Exercise2.ascx");
}

If i click in the button inside the usercontrol twice the program works,
but i would like only to need one click.
Thanks.
Josema.
Thanks.
Josema.

Nov 16 '05 #4
Hi,

Does the page is posted at the first click?

If so then the problem is in the if(!Postback) else {} part of the

Also remember that the dinamically added controls need to be recreated each
time the page is posted back

Maybe what is happening is that the first time you post the handler is not
kept, ( due a combination of the OnInit code or in the page_load checkig for
PostBack )
Then in the second postback it's kept and that is why you have to click
twice.

If this does not give you enought hints, post both the OnInit & the
Page_Load methods.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Josema" <Je******@ocu.org> wrote in message
news:74**********************************@microsof t.com...
Hi Ignacio, Mi problem is exactly this (in Web)
I have:
- an aspx page
- an ascx control (Exercise1.ascx)
- an ascx control (Exercise2.ascx)

Inside the aspx page i have a placeholder to add a control dinamically.
This placeholder's name is Exercise.

In the aspx page i have this in the OnInit:

override protected void OnInit(EventArgs e)
{
if(Page.Session["Exercise"]!=null)
{
switch(Page.Session["Exercise"].ToString())
{
case "Exercise2.ascx":
Exercise2 Exercise2_=(Exercise2)LoadControl("Exercise2.ascx" );
Exercise.Controls.Add(Exercise2_);
break;
}
}
else
{
Exercise1 Exercise1_=(Exercise1)LoadControl("Exercise1.ascx" );
Exercise.Controls.Add(Exercise1_);
}
}

In the (for instance) Exercise1.ascx i have this in the onClick method
of a button:

private void ExerciseBtn_Click(object sender, EventArgs e)
{
//add into the session the next exercise to load
Page.Session.Add("Exercise","Exercise2.ascx");
}

If i click in the button inside the usercontrol twice the program works,
but i would like only to need one click.
Thanks.
Josema.
Thanks.
Josema.


Nov 16 '05 #5


Hi,

I know that the problem its cause the onclick method its after the on
init, due this i have to click twice to see it working...

I would need to know how to add controls dinamically into a page,
mantaining the state of each control during each post-back, and (still
more difficult), each control that i add dinamically has controls that
makes posts-backs...

Could you give me some advices about it?

I will post the code i have here:
************************************************** *
*********************ASPX.cs FILE*********************
************************************************** *

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ASPX
{
/// <summary>
/// Summary description for MemoryBattery.
/// </summary>
public class MemoryBattery : System.Web.UI.Page
{
protected System.Web.UI.WebControls.PlaceHolder Exercise;
protected Exercise1 Exercise1_=new Exercise1();
protected Exercise2 Exercise2_=new Exercise2();

private void Page_Load(object sender, System.EventArgs e)
{

}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load +=new EventHandler(Page_Load);
if(Page.Session["Exercise"]!=null)
{
switch(Page.Session["Exercise"].ToString())
{
case "Exercise2.ascx":
Exercise2_=(Exercise2)LoadControl("Exercise2.ascx" );
Exercise.Controls.Add(Exercise2_);
break;
}
}
else
{
Exercise1_=(Exercise1)LoadControl("Exercise1.ascx" );
Exercise.Controls.Add(Exercise1_);
}
}
}
}

*********************************************
**************END OF THE ASPX.cs****************
********************************************

*********************************************
**************Exercise1.ascx ***************
********************************************

using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public class Exercise1 : System.Web.UI.UserControl
{
protected Button Button1;

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}

private void Button1_Click(object sender, EventArgs e)
{
//******this click its my problem, i would like that when
//the user clicks in this button, order to the aspx to
//load another control**********
Page.Session.Add("Exercise", "Exercise2.ascx");
}
}

************************************************
***************End Exercise1.ascx *****************
************************************************
Thanks.
Kind Regards.
Josema.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6

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

Similar topics

4
3880
by: Anatoly | last post by:
Put any control on web page. create Init event for ths control. Write Response.Write("here") inside this event. Compile\build\run. I never saw "here" string appear on web page. Why???
2
2167
by: jorge | last post by:
Hello I have the following situation: (everything is dynamic (controls.add)) 1. Button.Init { WasButtonClickFired = true } 2. TextBox.TextChanged { WasButtonClickFired?
3
6670
by: JD | last post by:
Hello, I have a problem with checkboxlist inside Repeater (in ASP.NET page). I am able to create Checkboxlist and bind it (inside Repeater_ItemBound - including setting checked/unchecked)....
4
4007
by: Mark Lingen | last post by:
I've found a problem with postback event handling and webcontrol buttons. Try out the following code in an ASP.Net project and you will see. Create a web project in VB.Net and drop this code...
1
5187
by: rmgalante | last post by:
I have written an ASP.Net application that uses the standard client-side and server-side validation for various fields on the form. Some of the customers that use the form report symptoms that...
6
2186
by: Shimon Sim | last post by:
I have Panel control on the page. I am handling Init event for it. It doesn't seem to fire at all. Why? Thank you Shimon.
2
4292
by: John A Grandy | last post by:
For ASP.NET UserControls , is it possible to provide multiple overrides of the intrinsic handler methods (those for which the delegate that wires the event to the handler is built-in , such as Init...
4
8442
by: Bob | last post by:
Hi, I'm working with VWD and i defined programmatically a button (in code-behind) with an ID. So I expect to see beside "Page Events" and "Form1" my button "b1" in order to use the Click event....
6
2248
by: Class | last post by:
Hi all, I create a gridview dynamicly because I don't know the columns in advance. I use the Templatefield to create a linkbutton. Everything fine..I have the postbackurl and it works. But now...
2
1407
by: =?Utf-8?B?SHV6ZWZh?= | last post by:
Hi, I am using a Multipage control with ASP.Net 1.1. The events for controls within the multipage are not getting fired. Any ideas why this would happen. It was working fine before i added...
0
7112
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,...
0
6974
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7146
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,...
0
7183
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5448
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,...
0
3084
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...
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
628
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.