how to fire custom server control events before Page_Load event

M

Michal Valent

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
 
B

bruce barker (sqlwork.com)

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)
 
M

Michal Valent

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)"
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top