|
-
Mar 13th, 2004, 09:37 AM
#1
Thread Starter
Frenzied Member
Events only fire when I refresh the page
I have a custom web control that has several events that bubble up from internal controls such as LinkButtons. When I use my control within a page and click one of these LinkButtons a postback takes place but the code inside that is supposed to execute OnLogout_Click does not fire:
Code:
void Logout_Click( object s, EventArgs e ) {
Session.Abandon();
FormsAuthentication.SignOut();
}
However if I refresh the page (F5) then the code is actioned. It is as if the page is rendering before the event is fired - which it probably is - how can I make sure it is fired first? BTW if it helps my control is built within CreateChildControls() rather than Render().
DJ
-
Mar 16th, 2004, 02:15 PM
#2
I wonder how many charact
In your Init_Event for your control....
put...
-
Mar 18th, 2004, 04:48 AM
#3
Thread Starter
Frenzied Member
Not sure where you are talking about - do you mean OnInit?
btw I think I know why it is not working.
CreateChildControls creates the child controls - at the time it is executed the events have not been fired and therefore any changes to properties after this point do not appear. Is there any way of delaying CreateChildControls being called until just before Rendertime?
Maybe I should convert the composite controls to render controls - but this would be a headache!
DJ
-
Mar 18th, 2004, 08:49 AM
#4
I wonder how many charact
You then want to handle these events in the OnPreRender... after the controls have been created, and viewstate restored (events), but before the control is actually rendered.
-
Mar 20th, 2004, 12:49 PM
#5
Thread Starter
Frenzied Member
I would like the events to be handled before createchildcontrols is called if this is possible.
DJ
-
Mar 20th, 2004, 04:15 PM
#6
I wonder how many charact
That's poses a problem then. How can the control in question handle the events before the control is even created?
You can still assign or change the way the control is rendered, even though you created it already. That's what the Prerender stage is for... so you can set a control to invisible, change its text, its enabled property after it has been created, but before its rendered.
-
Mar 21st, 2004, 09:47 AM
#7
Thread Starter
Frenzied Member
Ah right - yes I can see why that poses a problem. I might have to change the way the control is rendered - at present I am using a div created in a literalcontrol - the width of the control is concatonated into the div tag - once this is done in createchildcontrols I don't think it can be changed later on unless the whole literalcontrol is changed - it might be better to use a panel control instead as this would allow a width change within prerender.
I think I might be a bit stuck in a Classic ASP mindset rather than using ASP.NET controls that I can change attributes without the need for loads of if statements.
Thanks for all your help I'll look into it.
DJ
-
Mar 22nd, 2004, 06:51 AM
#8
I wonder how many charact
I resize my controls in the Prerender, and that works. But, everyone's situtation is different, and clearly, I couldn't begin to tell you how to solve yours.
-
Mar 22nd, 2004, 07:01 AM
#9
Thread Starter
Frenzied Member
Any chance you could post an example of using prerender to resize controls.
Thanks again for your help.
DJ
-
Mar 22nd, 2004, 07:33 AM
#10
I wonder how many charact
In the New constructor I set the control to a default size.
VB Code:
MyBase.New()
Me.Width = Unit.Pixel(200)
And then, I just call this from the OnPreRender method (or PreRender depending on what type of control you're building)
VB Code:
Private Sub adjustcontrolwidth()
'evalute space available for the two text boxes, give datebox little bit more
Dim w As Unit = Unit.Pixel(Convert.ToInt32(Me.Width.Value - 50) * 0.55)
Dim c As Unit = Unit.Pixel(Convert.ToInt32(Me.Width.Value - 50) * 0.45)
datebox.Width = w
If Not _isdateonly Then timebox.Width = c
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|