473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 9732
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**************@TK2MSFTNGP09.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.com> wrote in message
news:OO**************@TK2MSFTNGP09.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**************@TK2MSFTNGP09.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 IPostBackEventHandler interface and did
the following:

private static readonly object ClickEvent = new object();

public event EventHandler Click
{
add
{
Events.AddHandler(ClickEvent, value);
}
remove
{
Events.RemoveHandler(ClickEvent, value);
}
}

protected virtual void OnClick(EventArgs e)
{
EventHandler clickEventDelegate = (EventHandler)Events[ClickEvent];
if (clickEventDelegate != null)
clickEventDelegate(this, e);
}

public void RaisePostBackEvent(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*************@TK2MSFTNGP11.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.com> wrote in message
news:OO**************@TK2MSFTNGP09.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**************@TK2MSFTNGP09.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 RaiseBubbleEvent 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.btnDoSearch.Click += new
System.Web.UI.ImageClickEventHandler(this.btnDoSea rch_Click);

In the delegate method, raise the bubble event:

private void btnDoSearch_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
RaiseBubbleEvent(this, e);
}

Then, in your parent, capture the bubbled event.

protected override bool OnBubbleEvent(object sender, EventArgs e)
{
nextButton.Visible = 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, CommandEventArgs 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 IPostBackEventHandler interface and did
the following:

private static readonly object ClickEvent = new object();

public event EventHandler Click
{
add
{
Events.AddHandler(ClickEvent, value);
}
remove
{
Events.RemoveHandler(ClickEvent, value);
}
}

protected virtual void OnClick(EventArgs e)
{
EventHandler clickEventDelegate = (EventHandler)Events[ClickEvent];
if (clickEventDelegate != null)
clickEventDelegate(this, e);
}

public void RaisePostBackEvent(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*************@TK2MSFTNGP11.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.com> wrote in message
news:OO**************@TK2MSFTNGP09.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**************@TK2MSFTNGP09.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 RaiseBubbleEvent 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.btnDoSearch.Click += new
System.Web.UI.ImageClickEventHandler(this.btnDoSea rch_Click);

In the delegate method, raise the bubble event:

private void btnDoSearch_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
RaiseBubbleEvent(this, e);
}

Then, in your parent, capture the bubbled event.

protected override bool OnBubbleEvent(object sender, EventArgs e)
{
nextButton.Visible = 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, CommandEventArgs 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 IPostBackEventHandler interface and did the following:

private static readonly object ClickEvent = new object();

public event EventHandler Click
{
add
{
Events.AddHandler(ClickEvent, value);
}
remove
{
Events.RemoveHandler(ClickEvent, value);
}
}

protected virtual void OnClick(EventArgs e)
{
EventHandler clickEventDelegate = (EventHandler)Events[ClickEvent];
if (clickEventDelegate != null)
clickEventDelegate(this, e);
}

public void RaisePostBackEvent(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*************@TK2MSFTNGP11.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.com> wrote in message
news:OO**************@TK2MSFTNGP09.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**************@TK2MSFTNGP09.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
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...
3
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
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...
3
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"...
3
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...
1
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...
6
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...
6
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...
8
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...
2
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...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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...

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.