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

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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.


    John Guest

  2. Similar Questions and Discussions

    1. Urgent User Control
      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? ...
    2. URGENT! Error in web service function call - web services behavior
      I am getting the following message when trying to call a web service in javascript(from an ASP.NET application) using web services behavior: ...
    3. Internet Explorer Window Form User Control - Embed - Urgent
      Hi, This is URGENT, THANKS! Without getting into the "why", here's what I'd like to do, followed by where I am: 1. I would like to embed an...
    4. Urgent Question in Custom Paging User Control
      how is that an asp.net issue? isn't this a 3rd party control? what is the point of posting this message all over the net? -- Regards, Alvin...
  3. #2

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

    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:eeRLjuuSDHA.1552@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.
    >
    >

    William F. Robertson, Jr. Guest

  4. #3

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

    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:eeRLjuuSDHA.1552@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.
    >
    >

    S. Justin Gengo Guest

  5. #4

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

    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" <gengoj@krause.com> wrote in message
    news:vh8bimitne1r85@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:eeRLjuuSDHA.1552@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.
    > >
    > >
    >
    >

    John Guest

  6. #5

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

    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:
    [url]www.aboutfortunate.com[/url]

    "Out of chaos comes order."
    Nietzche


    "John" <a@b.com> wrote in message
    news:Orr1GK7SDHA.1912@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" <gengoj@krause.com> wrote in message
    > news:vh8bimitne1r85@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:eeRLjuuSDHA.1552@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.
    > > >
    > > >
    > >
    > >
    >
    >

    S. Justin Gengo Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139