473,396 Members | 1,933 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,396 software developers and data experts.

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.Save() 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 4260
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**************@TK2MSFTNGP10.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.Save() 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(ByVal source As Object, ByVal
args As System.EventArgs) As Boolean
'---Get the object that triggered the event
Select Case (source.GetType.ToString)
Case "System.Web.UI.WebControls.Button"
'---Get the button
Dim Button As Button = CType(source,
System.Web.UI.WebControls.Button)

'---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.ImageButton"
'---Find out which imagebutton was clicked

End Select
End Function

I hope this helps.

Justin

"John" <a@b.com> wrote in message
news:ee**************@TK2MSFTNGP10.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.Save() 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.supernews.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(ByVal source As Object, ByVal
args As System.EventArgs) As Boolean
'---Get the object that triggered the event
Select Case (source.GetType.ToString)
Case "System.Web.UI.WebControls.Button"
'---Get the button
Dim Button As Button = CType(source,
System.Web.UI.WebControls.Button)

'---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.ImageButton"
'---Find out which imagebutton was clicked

End Select
End Function

I hope this helps.

Justin

"John" <a@b.com> wrote in message
news:ee**************@TK2MSFTNGP10.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.Save() 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.Attributes.Add("onclick", "javascript:if (!confirm('Submit?') 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**************@TK2MSFTNGP12.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.supernews.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(ByVal source As Object, ByVal
args As System.EventArgs) As Boolean
'---Get the object that triggered the event
Select Case (source.GetType.ToString)
Case "System.Web.UI.WebControls.Button"
'---Get the button
Dim Button As Button = CType(source,
System.Web.UI.WebControls.Button)

'---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.ImageButton"
'---Find out which imagebutton was clicked

End Select
End Function

I hope this helps.

Justin

"John" <a@b.com> wrote in message
news:ee**************@TK2MSFTNGP10.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.Save() 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
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...
8
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...
9
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...
8
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...
7
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...
3
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...
3
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...
4
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...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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...
0
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...

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.