Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to fire custom server control events before Page_Load event

Reply
Thread Tools

how to fire custom server control events before Page_Load event

 
 
Michal Valent
Guest
Posts: n/a
 
      12-04-2007
I would like to fire some custom server control event before Page_Load event
like this (from the trace of an aspx page) :

Trace Information
Category Message From First(s) From Last(s)
aspx.page Begin PreInit
aspx.page End PreInit 5,38454603734274E-05 0,000054
aspx.page Begin Init 8,96405962016187E-05 0,000036
aspx.page End Init 0,00072941040948794 0,000640
aspx.page Begin InitComplete 0,000772971258380746 0,000044
aspx.page End InitComplete 0,000803692870689425 0,000031
aspx.page Begin LoadState 0,000834735021502791 0,000031
aspx.page End LoadState 0,00178558244517456 0,000951

aspx.page Begin ProcessPostData 0,00183099373614339 0,000045
customPaging.aspx Grid_PageIndexChanged 0,0109000220370222 0,009069 --- THE
CUSTOM SERVER CONTROL EVENT FIRED HERE
aspx.page End ProcessPostData 0,0742993505756337 0,063399

aspx.page Begin PreLoad 0,0743912900339237 0,000092
aspx.page End PreLoad 0,0744449925875471 0,000054
aspx.page Begin Load 0,0744761125357267 0,000031
customPaging.aspx Page_Load 0,0745075526885167 0,000031 --- THE PAGE LOAD
EVENT FIRED HERE
aspx.page End Load 0,0746396646365895 0,000132
aspx.page Begin ProcessPostData Second Try 0,0746623954910917 0,000023
aspx.page End ProcessPostData Second Try 0,0746837463605524 0,000021
aspx.page Begin Raise ChangedEvents 0,0747043760183775 0,000021
aspx.page End Raise ChangedEvents 0,0747389591179849 0,000035
aspx.page Begin Raise PostBackEvent 0,0747599143227289 0,000021
aspx.page End Raise PostBackEvent 0,0747898419344499 0,000030



According to the aspx page lifecycle - the custom server control events
could be fired in the

aspx.page Begin Raise PostBackEvent 0.099569 0.000043
aspx.page End Raise PostBackEvent 0.489606 0.360924

PostBackEvent section.



thanks
mike


 
Reply With Quote
 
 
 
 
bruce barker (sqlwork.com)
Guest
Posts: n/a
 
      12-04-2007
you keep asking this, but never say what you are trying to do, making it hard
for anyone to give a better answer than sure you can.

here is a custom textbox control that the TextChanged event before onload
(as soon as postback data is availiable).

public class MyTextBox : TextBox
{
protected override bool LoadPostData(
string postDataKey,
System.Collections.Specialized.NameValueCollection
postCollection)
{
bool returnValue = base.LoadPostData(postDataKey, postCollection);
base.RaisePostDataChangedEvent();
return returnValue;
}
protected override void RaisePostDataChangedEvent(){}
}

-- bruce (sqlwork.com)


"Michal Valent" wrote:

> I would like to fire some custom server control event before Page_Load event
> like this (from the trace of an aspx page) :
>
> Trace Information
> Category Message From First(s) From Last(s)
> aspx.page Begin PreInit
> aspx.page End PreInit 5,38454603734274E-05 0,000054
> aspx.page Begin Init 8,96405962016187E-05 0,000036
> aspx.page End Init 0,00072941040948794 0,000640
> aspx.page Begin InitComplete 0,000772971258380746 0,000044
> aspx.page End InitComplete 0,000803692870689425 0,000031
> aspx.page Begin LoadState 0,000834735021502791 0,000031
> aspx.page End LoadState 0,00178558244517456 0,000951
>
> aspx.page Begin ProcessPostData 0,00183099373614339 0,000045
> customPaging.aspx Grid_PageIndexChanged 0,0109000220370222 0,009069 --- THE
> CUSTOM SERVER CONTROL EVENT FIRED HERE
> aspx.page End ProcessPostData 0,0742993505756337 0,063399
>
> aspx.page Begin PreLoad 0,0743912900339237 0,000092
> aspx.page End PreLoad 0,0744449925875471 0,000054
> aspx.page Begin Load 0,0744761125357267 0,000031
> customPaging.aspx Page_Load 0,0745075526885167 0,000031 --- THE PAGE LOAD
> EVENT FIRED HERE
> aspx.page End Load 0,0746396646365895 0,000132
> aspx.page Begin ProcessPostData Second Try 0,0746623954910917 0,000023
> aspx.page End ProcessPostData Second Try 0,0746837463605524 0,000021
> aspx.page Begin Raise ChangedEvents 0,0747043760183775 0,000021
> aspx.page End Raise ChangedEvents 0,0747389591179849 0,000035
> aspx.page Begin Raise PostBackEvent 0,0747599143227289 0,000021
> aspx.page End Raise PostBackEvent 0,0747898419344499 0,000030
>
>
>
> According to the aspx page lifecycle - the custom server control events
> could be fired in the
>
> aspx.page Begin Raise PostBackEvent 0.099569 0.000043
> aspx.page End Raise PostBackEvent 0.489606 0.360924
>
> PostBackEvent section.
>
>
>
> thanks
> mike
>
>
>

 
Reply With Quote
 
 
 
 
Michal Valent
Guest
Posts: n/a
 
      12-05-2007
Thank you very much, bruce.

I was keep making the code like :

public class MyTextBox: Control, IPostBackDataHandler
{
public String Text {
get {
return (String) ViewState["Text"];
}

set {
ViewState["Text"] = value;
}
}

public event EventHandler TextChanged;

public virtual bool LoadPostData(string postDataKey,
NameValueCollection postCollection)
{
String presentValue = Text;
String postedValue = postCollection[postDataKey];

if (presentValue == null || !presentValue.Equals(postedValue)) {
Text = postedValue;
return true;
}

return false;
}


public virtual void RaisePostDataChangedEvent() {
OnTextChanged(EventArgs.Empty);
}


protected virtual void OnTextChanged(EventArgs e) {
if (TextChanged != null)
TextChanged(this,e);
}


protected override void Render(HtmlTextWriter output) {
output.Write("<INPUT type= text name = "+this.UniqueID
+ " value = " + this.Text + " >");
}
}

and the OnTextChanged event was fired after the page_load as expected.

Your code is doing the opposite.

The reason of my queries was just to understand IPostBackEventHandler and
IPostBackDataHandler derived custom server control,
and event fired from them.
The TextBox is derived from
public class TextBox : WebControl, IPostBackDataHandler,
IEditableTextControl, ITextControl.
The control in your code is derived from the TextBox.
I still don't understand why your code is doing the opposite as my
public class MyTextBox: Control, IPostBackDataHandler.

mike

"bruce barker (sqlwork.com)"
<(E-Mail Removed) > wrote in message
news:(E-Mail Removed)...
> you keep asking this, but never say what you are trying to do, making it
> hard
> for anyone to give a better answer than sure you can.
>
> here is a custom textbox control that the TextChanged event before onload
> (as soon as postback data is availiable).
>
> public class MyTextBox : TextBox
> {
> protected override bool LoadPostData(
> string postDataKey,
> System.Collections.Specialized.NameValueCollection
> postCollection)
> {
> bool returnValue = base.LoadPostData(postDataKey, postCollection);
> base.RaisePostDataChangedEvent();
> return returnValue;
> }
> protected override void RaisePostDataChangedEvent(){}
> }
>
> -- bruce (sqlwork.com)
>
>
> "Michal Valent" wrote:
>
>> I would like to fire some custom server control event before Page_Load
>> event
>> like this (from the trace of an aspx page) :
>>
>> Trace Information
>> Category Message From First(s) From Last(s)
>> aspx.page Begin PreInit
>> aspx.page End PreInit 5,38454603734274E-05 0,000054
>> aspx.page Begin Init 8,96405962016187E-05 0,000036
>> aspx.page End Init 0,00072941040948794 0,000640
>> aspx.page Begin InitComplete 0,000772971258380746 0,000044
>> aspx.page End InitComplete 0,000803692870689425 0,000031
>> aspx.page Begin LoadState 0,000834735021502791 0,000031
>> aspx.page End LoadState 0,00178558244517456 0,000951
>>
>> aspx.page Begin ProcessPostData 0,00183099373614339 0,000045
>> customPaging.aspx Grid_PageIndexChanged 0,0109000220370222 0,009069 ---
>> THE
>> CUSTOM SERVER CONTROL EVENT FIRED HERE
>> aspx.page End ProcessPostData 0,0742993505756337 0,063399
>>
>> aspx.page Begin PreLoad 0,0743912900339237 0,000092
>> aspx.page End PreLoad 0,0744449925875471 0,000054
>> aspx.page Begin Load 0,0744761125357267 0,000031
>> customPaging.aspx Page_Load 0,0745075526885167 0,000031 --- THE PAGE LOAD
>> EVENT FIRED HERE
>> aspx.page End Load 0,0746396646365895 0,000132
>> aspx.page Begin ProcessPostData Second Try 0,0746623954910917 0,000023
>> aspx.page End ProcessPostData Second Try 0,0746837463605524 0,000021
>> aspx.page Begin Raise ChangedEvents 0,0747043760183775 0,000021
>> aspx.page End Raise ChangedEvents 0,0747389591179849 0,000035
>> aspx.page Begin Raise PostBackEvent 0,0747599143227289 0,000021
>> aspx.page End Raise PostBackEvent 0,0747898419344499 0,000030
>>
>>
>>
>> According to the aspx page lifecycle - the custom server control events
>> could be fired in the
>>
>> aspx.page Begin Raise PostBackEvent 0.099569 0.000043
>> aspx.page End Raise PostBackEvent 0.489606 0.360924
>>
>> PostBackEvent section.
>>
>>
>>
>> thanks
>> mike
>>
>>
>>



 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
custom server control event before Page_Load fired Michal Valent ASP .Net 2 11-27-2007 04:25 PM
Custom server control running code before page_load? Daves ASP .Net 10 05-11-2005 03:34 PM
Fire server side event before client side event ASP .Net Web Controls 3 03-18-2005 03:20 PM
Why does page_load fire twice when inheriting from a common overridable Page_Load bminder ASP .Net 1 02-23-2004 08:54 PM



Advertisments