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

F

Fabrizio

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
 
A

Alessandro Zifiglio

hi Fabrizio, I'm not clear with what you want to do. Can you provide another
scenario without using Map, ZoomIn etc.
Fabrizio said:
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
 
A

Alessandro Zifiglio

Actually some demo code would be nice too ;P

Alessandro Zifiglio said:
hi Fabrizio, I'm not clear with what you want to do. Can you provide another
scenario without using Map, ZoomIn etc.
without
touching the user control, so in user control page_load i check is
fired after the user control page_load and i load the map twice for every
event.
user control are pending ? Or a tip to handle the situation in a more
intelligent way
 
F

Fabrizio

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
 
A

Alessandro Zifiglio

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 said:
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.
 
A

Alessandro Zifiglio

lol fabrizio ;P
You are welcome :)
Fabrizio said:
Very good tips and explanation Alessandro (both italian and both chatting
in english? :) ), thanks for your kind help.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top