473,883 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User Control Postback

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 successfully (return the count of a sql
query) in the Page_Load of the webform is too soon, since the Page_Load
event of the webform is raised before anything happens on the user control.

How can my user control "notify" my webform that it has successfully
completed postback?
Nov 18 '05 #1
5 9752
How does the page know that anything happened on the control? Does the user
control raise an event? If it does, you can enable the button in the event
handler.

Eliyahu

"George Durzi" <gd****@hotmail .com> wrote in message
news:uo******** ******@TK2MSFTN GP09.phx.gbl...
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 successfully (return the count of a sql
query) in the Page_Load of the webform is too soon, since the Page_Load
event of the webform is raised before anything happens on the user control.
How can my user control "notify" my webform that it has successfully
completed postback?

Nov 18 '05 #2
>> How does the page know that anything happened on the control?
That's what I'm trying to figure out. Can I define a custom event that the
user control would raise? The webform would capture that event.

Can you point me to an example that demonstrates that?

Thank you
"Eliyahu Goldin" <re************ *@monarchmed.co m> wrote in message
news:OO******** ******@TK2MSFTN GP09.phx.gbl...
How does the page know that anything happened on the control? Does the user control raise an event? If it does, you can enable the button in the event
handler.

Eliyahu

"George Durzi" <gd****@hotmail .com> wrote in message
news:uo******** ******@TK2MSFTN GP09.phx.gbl...
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 successfully (return the count of a sql
query) in the Page_Load of the webform is too soon, since the Page_Load
event of the webform is raised before anything happens on the user

control.

How can my user control "notify" my webform that it has successfully
completed postback?


Nov 18 '05 #3
In my user control I implemented the IPostBackEventH andler interface and did
the following:

private static readonly object ClickEvent = new object();

public event EventHandler Click
{
add
{
Events.AddHandl er(ClickEvent, value);
}
remove
{
Events.RemoveHa ndler(ClickEven t, value);
}
}

protected virtual void OnClick(EventAr gs e)
{
EventHandler clickEventDeleg ate = (EventHandler)E vents[ClickEvent];
if (clickEventDele gate != null)
clickEventDeleg ate(this, e);
}

public void RaisePostBackEv ent(String eventArgument)
{
OnClick(new EventArgs());
}

Am I on the right track? How would a webform that has this user control in
it, consume this event?

"George Durzi" <gd****@hotmail .com> wrote in message
news:uP******** *****@TK2MSFTNG P11.phx.gbl...
How does the page know that anything happened on the control? That's what I'm trying to figure out. Can I define a custom event that the
user control would raise? The webform would capture that event.

Can you point me to an example that demonstrates that?

Thank you
"Eliyahu Goldin" <re************ *@monarchmed.co m> wrote in message
news:OO******** ******@TK2MSFTN GP09.phx.gbl...
How does the page know that anything happened on the control? Does the

user
control raise an event? If it does, you can enable the button in the event handler.

Eliyahu

"George Durzi" <gd****@hotmail .com> wrote in message
news:uo******** ******@TK2MSFTN GP09.phx.gbl...
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 successfully (return the count of a sql query) in the Page_Load of the webform is too soon, since the Page_Load event of the webform is raised before anything happens on the user

control.

How can my user control "notify" my webform that it has successfully
completed postback?



Nov 18 '05 #4
You are putting too much work into this. Use RaiseBubbleEven t to
communicate to the parent that a click has been executed. While
creating your own events and handlers certainly make sense in some
cases, for simple child to parent communication, intrinsic event
management should suffice.

So:

Bind the button click to some delegate in your control, for instance:

this.btnDoSearc h.Click += new
System.Web.UI.I mageClickEventH andler(this.btn DoSearch_Click) ;

In the delegate method, raise the bubble event:

private void btnDoSearch_Cli ck(object sender,
System.Web.UI.I mageClickEventA rgs e)
{
RaiseBubbleEven t(this, e);
}

Then, in your parent, capture the bubbled event.

protected override bool OnBubbleEvent(o bject sender, EventArgs e)
{
nextButton.Visi ble = true

return true;
}

This is of course a short, raw version of the idea. You'll probably
modify it to your own needs and make it more robust. For instance, you
should check the sender object to ensure that the bubble event is coming
from the correct control. Also, you might want to create your own
custom event arguments, CommandEventArg s for instance, that you could
use to send more information about your control's click event to the parent.

Makes sense?

ib.
George Durzi wrote:
In my user control I implemented the IPostBackEventH andler interface and did
the following:

private static readonly object ClickEvent = new object();

public event EventHandler Click
{
add
{
Events.AddHandl er(ClickEvent, value);
}
remove
{
Events.RemoveHa ndler(ClickEven t, value);
}
}

protected virtual void OnClick(EventAr gs e)
{
EventHandler clickEventDeleg ate = (EventHandler)E vents[ClickEvent];
if (clickEventDele gate != null)
clickEventDeleg ate(this, e);
}

public void RaisePostBackEv ent(String eventArgument)
{
OnClick(new EventArgs());
}

Am I on the right track? How would a webform that has this user control in
it, consume this event?

"George Durzi" <gd****@hotmail .com> wrote in message
news:uP******** *****@TK2MSFTNG P11.phx.gbl...
How does the page know that anything happened on the control?


That's what I'm trying to figure out. Can I define a custom event that the
user control would raise? The webform would capture that event.

Can you point me to an example that demonstrates that?

Thank you
"Eliyahu Goldin" <re************ *@monarchmed.co m> wrote in message
news:OO****** ********@TK2MSF TNGP09.phx.gbl. ..
How does the page know that anything happened on the control? Does the


user
control raise an event? If it does, you can enable the button in the
event
handler.

Eliyahu

"George Durzi" <gd****@hotmail .com> wrote in message
news:uo***** *********@TK2MS FTNGP09.phx.gbl ...

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 successfully (return the count of a
sql
query) in the Page_Load of the webform is too soon, since the
Page_Load
event of the webform is raised before anything happens on the user

control.

How can my user control "notify" my webform that it has successfully
completed postback?


Nov 18 '05 #5
Ireney, thank you. That worked perfectly.

"Ireney Berezniak" <ir************ **@gmail.com> wrote in message
news:DyICc.8$o4 .2@clgrps13...
You are putting too much work into this. Use RaiseBubbleEven t to
communicate to the parent that a click has been executed. While
creating your own events and handlers certainly make sense in some
cases, for simple child to parent communication, intrinsic event
management should suffice.

So:

Bind the button click to some delegate in your control, for instance:

this.btnDoSearc h.Click += new
System.Web.UI.I mageClickEventH andler(this.btn DoSearch_Click) ;

In the delegate method, raise the bubble event:

private void btnDoSearch_Cli ck(object sender,
System.Web.UI.I mageClickEventA rgs e)
{
RaiseBubbleEven t(this, e);
}

Then, in your parent, capture the bubbled event.

protected override bool OnBubbleEvent(o bject sender, EventArgs e)
{
nextButton.Visi ble = true

return true;
}

This is of course a short, raw version of the idea. You'll probably
modify it to your own needs and make it more robust. For instance, you
should check the sender object to ensure that the bubble event is coming
from the correct control. Also, you might want to create your own
custom event arguments, CommandEventArg s for instance, that you could
use to send more information about your control's click event to the parent.
Makes sense?

ib.
George Durzi wrote:
In my user control I implemented the IPostBackEventH andler interface and did the following:

private static readonly object ClickEvent = new object();

public event EventHandler Click
{
add
{
Events.AddHandl er(ClickEvent, value);
}
remove
{
Events.RemoveHa ndler(ClickEven t, value);
}
}

protected virtual void OnClick(EventAr gs e)
{
EventHandler clickEventDeleg ate = (EventHandler)E vents[ClickEvent];
if (clickEventDele gate != null)
clickEventDeleg ate(this, e);
}

public void RaisePostBackEv ent(String eventArgument)
{
OnClick(new EventArgs());
}

Am I on the right track? How would a webform that has this user control in it, consume this event?

"George Durzi" <gd****@hotmail .com> wrote in message
news:uP******** *****@TK2MSFTNG P11.phx.gbl...
>How does the page know that anything happened on the control?

That's what I'm trying to figure out. Can I define a custom event that theuser control would raise? The webform would capture that event.

Can you point me to an example that demonstrates that?

Thank you
"Eliyahu Goldin" <re************ *@monarchmed.co m> wrote in message
news:OO****** ********@TK2MSF TNGP09.phx.gbl. ..

How does the page know that anything happened on the control? Does the

user

control raise an event? If it does, you can enable the button in the


event
handler.

Eliyahu

"George Durzi" <gd****@hotmail .com> wrote in message
news:uo***** *********@TK2MS FTNGP09.phx.gbl ...

>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 successfully (return the count of a


sql
>query) in the Page_Load of the webform is too soon, since the


Page_Load
>event of the webform is raised before anything happens on the user

control.

>How can my user control "notify" my webform that it has successfully
>completed postback?
>
>


Nov 18 '05 #6

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

Similar topics

2
3412
by: Duwayne | last post by:
I am having lots of trouble with one of my user controls (ascx) not automatically loading postback data. An image on the aspx page starts the postback and the parent has no problem loading it's own information, but when it comes to loading the data for the user control, nothing loads. From my understanding, during postback, the user control should reload the new information based on the postback. Some information: The aspx dynamically...
3
3010
by: Cathie | last post by:
Hi All, I have a few user controls on a page and I need to determine which control caused the PostBack. Is there anyway to do this? Thanks in advance, Cathie
7
5738
by: moondaddy | last post by:
I'm building a page in vb.net with several user controls on it. I'm using user controls instead of a frames page since I've seen this recommended many times in this user group. I want just one of the user controls to do a postback but not the rest of the page. Is this possible? it seems like it should be. If it is, please explain how I can do it. Thanks. -- moondaddy@nospam.com
3
8533
by: buran | last post by:
Dear ASP.NET Programmers, I am loading a web user control ("taclient.ascx") into a placeholder (ID: phFA). The web user control contains a cancel button (ID: btnCancel). I would like to "unload" the web user control when the user clicks on the cancel button. How can I accomplish this? Thanks in advance. dim myControl as Control myControl = LoadControl("taclient.ascx") phFA.Controls.Clear()
3
16110
by: Guadala Harry | last post by:
I have a simple user control (see below) that has EnableViewState="true". I place it on an ASPX page at runtime using a PlaceHolder - which also has EnableViewState="true". After a postback, the aspx page renders back to the client, but the user control is not on the rendered page. Why? I thought ViewState was supposed to keep things intact between postbacks. FWIW: during the postback the code does nothing with respect to the user...
1
2144
by: Robert Howells | last post by:
Perhaps I'm just too new at this to pull it off, or perhaps it's just bad architecture. I'd appreciate some feedback on the the wisdom (or lack thereof) in attempting the following: I'm not new to programming, but I am new to ASP.NET and Web application design in general... loved the concept of user controls and dynamically adding them to a page. So what I wound up with was an application that dynamically loads two user controls directly...
6
1815
by: Jim | last post by:
I have a user control that I am dynamically loading into an aspx page. When I fill out the text boxes and submit the form using a command button on the aspx page I lose the value from the user control. I have an Error-checking function in the user control that I invoke from the aspx page. This method fires and detects an error even though I fill the the text box with text. Now, if I fill out the text box again with text everything goes...
6
3387
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...
8
17010
by: Mats Lycken | last post by:
Hi, I'm working on a webproject where I have several different user controls loaded on a WebForm. A problem arises when I in one webcontrol makes a change that should be picked up by another user control. For example a webshop. I have a datagrid of products in the shopping cart in one user control. In another I have an overview of the shopping cart (lists the products and a shows an order total). When I remove a product from my datagrid...
2
15083
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have been able to find the cause of the problem, and will describe it here first textually and then through a code example. The purpose of what I am trying to do is to create a postback-free web application through the use of ASP.net AJAX UpdatePanels...
0
9940
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
11142
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...
0
10743
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10847
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
10415
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9574
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
7971
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...
1
4612
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 we have to send another system
3
3232
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.