472,117 Members | 2,563 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,117 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 4144
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Meg | last post: by
8 posts views Thread by Prince Mathew | last post: by
3 posts views Thread by N. Spiker | last post: by
reply views Thread by leo001 | last post: by

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.