473,703 Members | 2,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Urgent : Unsure of when to call a function within a user control

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':

1. In the Page_Load event of the PAGE, I call LoadControl to load the user
control (I need to do this to restore viewstate)
2. Immediately after the LoadControl call, I call myusercontrol.S ave() but
the viewstate has not been restored since the Page_Load event of the user
control hasn't fired.

so I then tried :

1. In the Page_Load event of the PAGE, I call LoadControl to load the user
control (I need to do this to restore viewstate)
2. Immediately after the LoadControl call, I populate a session variable to
use in the Page_Load event of my user control.
3. The Page_Load event of my user control fires (because the Page_Load event
of my PAGE ended normally)
4. Right at the end of the Page_Load event of my user control, I call the
Save method contained within but during the save, I don't have access to the
controls on my form (agaion, a viewstate problem).

Exactly where am I supposed to call the public Save method of my user
control?

I hope I've explained clearly as this needs a good, proper solution asap.
Thankyou!

Regards
John.
Nov 17 '05 #1
4 4285
Why don't you wire the Save method of your user control to the click
function that is submitting the form? That way, after you LoadControl, the
event will be wired and when the click event is sent, it will run the Save
method?

bill
"John" <a@b.com> wrote in message
news:ee******** ******@TK2MSFTN GP10.phx.gbl...
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':

1. In the Page_Load event of the PAGE, I call LoadControl to load the user
control (I need to do this to restore viewstate)
2. Immediately after the LoadControl call, I call myusercontrol.S ave() but
the viewstate has not been restored since the Page_Load event of the user
control hasn't fired.

so I then tried :

1. In the Page_Load event of the PAGE, I call LoadControl to load the user
control (I need to do this to restore viewstate)
2. Immediately after the LoadControl call, I populate a session variable to use in the Page_Load event of my user control.
3. The Page_Load event of my user control fires (because the Page_Load event of my PAGE ended normally)
4. Right at the end of the Page_Load event of my user control, I call the
Save method contained within but during the save, I don't have access to the controls on my form (agaion, a viewstate problem).

Exactly where am I supposed to call the public Save method of my user
control?

I hope I've explained clearly as this needs a good, proper solution asap.
Thankyou!

Regards
John.

Nov 17 '05 #2
John,

I'm also using dynamically loaded user controls and I also restore the
controls to access view state properties when the form is submitted.

I then call my save, delete, etc. functions using the OnBubbleEvent.

Any button in a user control automatically "bubbles" it's click event (and
the others too...) up to the page the control is hosted on.

Here's a small sample to get you going...

Protected Overrides Function OnBubbleEvent(B yVal source As Object, ByVal
args As System.EventArg s) As Boolean
'---Get the object that triggered the event
Select Case (source.GetType .ToString)
Case "System.Web.UI. WebControls.But ton"
'---Get the button
Dim Button As Button = CType(source,
System.Web.UI.W ebControls.Butt on)

'---Find out which button was clicked
Select Case Button.Id
Case "Submit"
'---Call the submit sub
Call MySubmitSub()

Case "Delete"
'---Call the delete sub
Call MyDeleteSub()

End Select

Case "System.Web.UI. WebControls.Ima geButton"
'---Find out which imagebutton was clicked

End Select
End Function

I hope this helps.

Justin

"John" <a@b.com> wrote in message
news:ee******** ******@TK2MSFTN GP10.phx.gbl...
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':

1. In the Page_Load event of the PAGE, I call LoadControl to load the user
control (I need to do this to restore viewstate)
2. Immediately after the LoadControl call, I call myusercontrol.S ave() but
the viewstate has not been restored since the Page_Load event of the user
control hasn't fired.

so I then tried :

1. In the Page_Load event of the PAGE, I call LoadControl to load the user
control (I need to do this to restore viewstate)
2. Immediately after the LoadControl call, I populate a session variable to use in the Page_Load event of my user control.
3. The Page_Load event of my user control fires (because the Page_Load event of my PAGE ended normally)
4. Right at the end of the Page_Load event of my user control, I call the
Save method contained within but during the save, I don't have access to the controls on my form (agaion, a viewstate problem).

Exactly where am I supposed to call the public Save method of my user
control?

I hope I've explained clearly as this needs a good, proper solution asap.
Thankyou!

Regards
John.

Nov 17 '05 #3
O.K. thanks. I hear what you're saying but the form is submitted via a
javascript. I display a confirm box and if the user clicks OK, I use the
form.submit() method. What do I do then?
"S. Justin Gengo" <ge****@krause. com> wrote in message
news:vh******** ****@corp.super news.com...
John,

I'm also using dynamically loaded user controls and I also restore the
controls to access view state properties when the form is submitted.

I then call my save, delete, etc. functions using the OnBubbleEvent.

Any button in a user control automatically "bubbles" it's click event (and
the others too...) up to the page the control is hosted on.

Here's a small sample to get you going...

Protected Overrides Function OnBubbleEvent(B yVal source As Object, ByVal
args As System.EventArg s) As Boolean
'---Get the object that triggered the event
Select Case (source.GetType .ToString)
Case "System.Web.UI. WebControls.But ton"
'---Get the button
Dim Button As Button = CType(source,
System.Web.UI.W ebControls.Butt on)

'---Find out which button was clicked
Select Case Button.Id
Case "Submit"
'---Call the submit sub
Call MySubmitSub()

Case "Delete"
'---Call the delete sub
Call MyDeleteSub()

End Select

Case "System.Web.UI. WebControls.Ima geButton"
'---Find out which imagebutton was clicked

End Select
End Function

I hope this helps.

Justin

"John" <a@b.com> wrote in message
news:ee******** ******@TK2MSFTN GP10.phx.gbl...
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':

1. In the Page_Load event of the PAGE, I call LoadControl to load the user control (I need to do this to restore viewstate)
2. Immediately after the LoadControl call, I call myusercontrol.S ave() but the viewstate has not been restored since the Page_Load event of the user control hasn't fired.

so I then tried :

1. In the Page_Load event of the PAGE, I call LoadControl to load the user control (I need to do this to restore viewstate)
2. Immediately after the LoadControl call, I populate a session variable

to
use in the Page_Load event of my user control.
3. The Page_Load event of my user control fires (because the Page_Load

event
of my PAGE ended normally)
4. Right at the end of the Page_Load event of my user control, I call the Save method contained within but during the save, I don't have access to

the
controls on my form (agaion, a viewstate problem).

Exactly where am I supposed to call the public Save method of my user
control?

I hope I've explained clearly as this needs a good, proper solution asap. Thankyou!

Regards
John.


Nov 17 '05 #4
Why are you using form.submit()?

Instead why don't you attach the javascript confirm to the regular submit
button?

Button.Attribut es.Add("onclick ", "javascript :if (!confirm('Subm it?') return
false;")

This way you would be able to use the submit button's onclick event.

--
S. Justin Gengo, MCP
Web Developer / Programmer

Free Code Library At:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"John" <a@b.com> wrote in message
news:Or******** ******@TK2MSFTN GP12.phx.gbl...
O.K. thanks. I hear what you're saying but the form is submitted via a
javascript. I display a confirm box and if the user clicks OK, I use the
form.submit() method. What do I do then?
"S. Justin Gengo" <ge****@krause. com> wrote in message
news:vh******** ****@corp.super news.com...
John,

I'm also using dynamically loaded user controls and I also restore the
controls to access view state properties when the form is submitted.

I then call my save, delete, etc. functions using the OnBubbleEvent.

Any button in a user control automatically "bubbles" it's click event (and
the others too...) up to the page the control is hosted on.

Here's a small sample to get you going...

Protected Overrides Function OnBubbleEvent(B yVal source As Object, ByVal
args As System.EventArg s) As Boolean
'---Get the object that triggered the event
Select Case (source.GetType .ToString)
Case "System.Web.UI. WebControls.But ton"
'---Get the button
Dim Button As Button = CType(source,
System.Web.UI.W ebControls.Butt on)

'---Find out which button was clicked
Select Case Button.Id
Case "Submit"
'---Call the submit sub
Call MySubmitSub()

Case "Delete"
'---Call the delete sub
Call MyDeleteSub()

End Select

Case "System.Web.UI. WebControls.Ima geButton"
'---Find out which imagebutton was clicked

End Select
End Function

I hope this helps.

Justin

"John" <a@b.com> wrote in message
news:ee******** ******@TK2MSFTN GP10.phx.gbl...
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':

1. In the Page_Load event of the PAGE, I call LoadControl to load the user control (I need to do this to restore viewstate)
2. Immediately after the LoadControl call, I call myusercontrol.S ave() but the viewstate has not been restored since the Page_Load event of the user control hasn't fired.

so I then tried :

1. In the Page_Load event of the PAGE, I call LoadControl to load the user control (I need to do this to restore viewstate)
2. Immediately after the LoadControl call, I populate a session
variable to
use in the Page_Load event of my user control.
3. The Page_Load event of my user control fires (because the Page_Load

event
of my PAGE ended normally)
4. Right at the end of the Page_Load event of my user control, I call the Save method contained within but during the save, I don't have access
to the
controls on my form (agaion, a viewstate problem).

Exactly where am I supposed to call the public Save method of my user
control?

I hope I've explained clearly as this needs a good, proper solution

asap. Thankyou!

Regards
John.



Nov 17 '05 #5

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

Similar topics

0
1697
by: Meg | last post by:
Hi, I have a listbox with a number of items. When I click one of the items I am loading a user control. When another item is selected I am loading a different user control. I am loading the user control in the SelectedIndexChanged event of the listbox. The user control is getting loaded. When I add some values in the controls of the User Control and I am trying to
8
5255
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is developing a web-based application, one part of which involves allowing the user the ability to page through transaction "history" information. The _summary_ history table will have the following fields: ServiceName, Date, User-Ref1, User-Ref2,...
9
2176
by: Moe Sizlak | last post by:
Hi There, I am trying to write the selected value of a listcontrol when a button is clicked and I keep getting the error "object not set to a reference of an object". The libox itself is in a usercontrol and all i'm really needing to do is get the selected value when the button is clicked on the form. Can someone tell what I need to include in my page to get this working ? Moe <><
8
1495
by: Prince Mathew | last post by:
Hi All, I have a requirement. I am throwing an exception from my user control I want to catch this in my container page. Is this possible? I don't want any event to be raised. PLEASE HELP ME.
7
1934
by: John | last post by:
Hi all, I need finality on this once and for all please. I have a main page which contains a couple of placeholders and within these placeholders, depending on what the user presses, I load different user controls. This loading of user controls is done within the code-behind of the main page. The problem is that before loading a user control in place of another, I need to do a Controls.Add then a Controls.Remove so the viewstate is...
3
13606
by: anadimpa | last post by:
Hello all I build a javascript function string in the code behind and register it in the Page_Load of my User Control. I do this because I build the javascript based on some variables that are passed to this user control. How do I (or from where do I) call this function? I tried several ways like: this.Attributes.Add("onLoad", "javascript:openDoc();"); in the page_load / page_prerender etc...
3
6467
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from the socket is missing the last character (line feed). When the same text is sent without the urgent flag set, all of the characters are read. I'm reading the data using the blocking read call of the network stream class. The .NET...
4
4636
by: grayaii | last post by:
Hi, I have a simple form that handles all its paint functionality like so: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); And the entry point to this program is like so: static void Main() {
4
2085
by: Regnab | last post by:
I've got a form - "frmLookup" (with a subform) that works very happily on its own. The form has a list box, which when updated requeries the subform to display the appropriate results. The problem is that for the final user interface, I had planned to use a "frmDisplay" form which had a number of menu items and then depending on what the user selected, it would display the appropraite form in a subform beneath the menu items. I did this...
0
8761
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
8672
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8969
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
7876
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...
0
5923
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
4434
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
4689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3125
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
2070
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.