Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Know in user control page_load if an user control event is going to be fired

Reply
Thread Tools

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

 
 
Fabrizio
Guest
Posts: n/a
 
      02-23-2004
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
 
Reply With Quote
 
 
 
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      02-24-2004
hi Fabrizio, I'm not clear with what you want to do. Can you provide another
scenario without using Map, ZoomIn etc.
"Fabrizio" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      02-24-2004
Actually some demo code would be nice too ;P

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

another
> scenario without using Map, ZoomIn etc.
> "Fabrizio" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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

>
>



 
Reply With Quote
 
Fabrizio
Guest
Posts: n/a
 
      02-24-2004
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
 
Reply With Quote
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      02-24-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      02-24-2004
lol fabrizio ;P
You are welcome
"Fabrizio" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Very good tips and explanation Alessandro (both italian and both chatting

in english? ), thanks for your kind help.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Embedded <divs> with events: How to prevent the parent div's eventfrom being fired when the embedded div's event is fired? Num GG Javascript 2 11-17-2008 08:56 PM
custom server control event before Page_Load fired Michal Valent ASP .Net 2 11-27-2007 04:25 PM
Materpage page_load event fired after content page_load? rockdale ASP .Net 1 11-16-2006 06:59 PM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Building Controls 1 05-28-2004 06:23 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net 2 05-25-2004 11:45 PM



Advertisments