Know in user control page_load if an user control event is going to be fired

Discussion in 'ASP .Net Building Controls' started by Fabrizio, Feb 23, 2004.

  1. Fabrizio

    Fabrizio Guest

    Hi all,
    i have built a user control that shows a map and let the user zoom in, out, usual stuff.
    Putting this object in a webform the user can cause page postback without touching the user control, so in user control page_load i check
    if not ib_MapLoaded then LoadMap

    Unluckily with this logic if the user ask for a ZoomIn the ZoomIn_Click is fired after the user control page_load and i load the map twice for every event.
    Is there a way to know in user control page_load if other event of the user control are pending ? Or a tip to handle the situation in a more intelligent way

    Tks in advance
    Fabrizio, Feb 23, 2004
    #1
    1. Advertising

  2. hi Fabrizio, I'm not clear with what you want to do. Can you provide another
    scenario without using Map, ZoomIn etc.
    "Fabrizio" <> wrote in message
    news:...
    > Hi all,
    > i have built a user control that shows a map and let the user zoom in,

    out, usual stuff.
    > Putting this object in a webform the user can cause page postback without

    touching the user control, so in user control page_load i check
    > if not ib_MapLoaded then LoadMap
    >
    > Unluckily with this logic if the user ask for a ZoomIn the ZoomIn_Click is

    fired after the user control page_load and i load the map twice for every
    event.
    > Is there a way to know in user control page_load if other event of the

    user control are pending ? Or a tip to handle the situation in a more
    intelligent way
    >
    > Tks in advance
    Alessandro Zifiglio, Feb 24, 2004
    #2
    1. Advertising

  3. Actually some demo code would be nice too ;P

    "Alessandro Zifiglio" <> wrote in
    message news:FkG_b.11046$...
    > hi Fabrizio, I'm not clear with what you want to do. Can you provide

    another
    > scenario without using Map, ZoomIn etc.
    > "Fabrizio" <> wrote in message
    > news:...
    > > Hi all,
    > > i have built a user control that shows a map and let the user zoom in,

    > out, usual stuff.
    > > Putting this object in a webform the user can cause page postback

    without
    > touching the user control, so in user control page_load i check
    > > if not ib_MapLoaded then LoadMap
    > >
    > > Unluckily with this logic if the user ask for a ZoomIn the ZoomIn_Click

    is
    > fired after the user control page_load and i load the map twice for every
    > event.
    > > Is there a way to know in user control page_load if other event of the

    > user control are pending ? Or a tip to handle the situation in a more
    > intelligent way
    > >
    > > Tks in advance

    >
    >
    Alessandro Zifiglio, Feb 24, 2004
    #3
  4. Fabrizio

    Fabrizio Guest

    Eh, sorry for being not so clear
    Thinking about it i can set the question in a much simple way (the code i could show would not clear the nature of the problem, it's all in my mind :))
    Being in the Page_Load of a WebForm how can i know if an event is going to fire ? a button_click, a grid_itemcommand, and so on
    Can i see also events fired in a user control in the web form
    Can i see the event also in the page load of the user control
    And a last question connected, how do i call a __PostBack from javascript in the correct manner

    P.S. Speaking about my problem i found really good use of the Page_PreRender event, but i would still like to know if i can get this information

    I hope i've been clear, instead i'll try to be more
    Thanks
    Fabrizio
    Fabrizio, Feb 24, 2004
    #4
  5. Fabrizio,
    In page load you can check to see who fired the event depending on the type
    of webcontrol, one of these always works :
    If Request.Params.Item("btnSubmit") <> Nothing Then
    Else
    End If

    If Request.Params("btnSubmit") <> Nothing Then
    Else
    End If

    If Request.Form("btnSubmit") <> Nothing Then
    Else
    End If
    dim s as string
    s = Request.Params.Get("__EVENTTARGET")

    If s = "btnSubmit" then
    Else
    End if

    As for you dataGrid events you will have to code inside the appropriate
    methods exposed by the dataGrid. This control is a container control and all
    events fired within this container are bubbled up and handled within the
    handlers exposed by this control. A good place to check for click events is
    the OnItemCommad method. This allows you to provide a custom handler for
    the event.


    For your last question, as you would have already noted when using controls
    that postback in asp.net, some javascript code is injected into your page :
    <script language="javascript">
    <!--
    function __doPostBack(eventTarget, eventArgument) {
    var theform = document.myForm;
    theform.__EVENTTARGET.value = eventTarget;
    theform.__EVENTARGUMENT.value = eventArgument;
    theform.submit();
    }
    // -->
    </script>

    this is the __doPostBack function which is called by any of our controls
    that postback. What it does is it takes an eventTarget(the control ID that
    is postback) and an eventArgument(this is extra info you might want to pass
    along with the event) and sets these values into the hiddenfields before
    causing the form to submit. This is how your webform knows who postback etc.
    You can call this funtion from any clientside code you might have and pass
    it an id.

    Please note however that this script is injected into the page only when
    there is a control on your webform that postsback, so for you to be able to
    call this function from your clientside code you need to have atleast one
    control on your webform that postsback. otherwise you would be calling
    _doPostBack but the function is never there coz it was never injected into
    your page.



    "Fabrizio" <> wrote in message
    news:...
    > Eh, sorry for being not so clear.
    > Thinking about it i can set the question in a much simple way (the code i

    could show would not clear the nature of the problem, it's all in my mind
    :)).
    > Being in the Page_Load of a WebForm how can i know if an event is going to

    fire ? a button_click, a grid_itemcommand, and so on.
    > Can i see also events fired in a user control in the web form ?
    > Can i see the event also in the page load of the user control ?
    > And a last question connected, how do i call a __PostBack from javascript

    in the correct manner ?
    >
    > P.S. Speaking about my problem i found really good use of the

    Page_PreRender event, but i would still like to know if i can get this
    information.
    >
    > I hope i've been clear, instead i'll try to be more.
    > Thanks,
    > Fabrizio
    Alessandro Zifiglio, Feb 24, 2004
    #5
  6. lol fabrizio ;P
    You are welcome :)
    "Fabrizio" <> wrote in message
    news:...
    > Very good tips and explanation Alessandro (both italian and both chatting

    in english? :) ), thanks for your kind help.
    Alessandro Zifiglio, Feb 24, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jorge
    Replies:
    2
    Views:
    1,265
    jorge
    May 26, 2004
  2. rockdale
    Replies:
    1
    Views:
    658
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Nov 16, 2006
  3. Michal Valent
    Replies:
    2
    Views:
    414
    Michal Valent
    Nov 27, 2007
  4. jorge
    Replies:
    1
    Views:
    411
    Teemu Keiski
    May 28, 2004
  5. jorge
    Replies:
    0
    Views:
    329
    jorge
    May 25, 2004
Loading...

Share This Page