I am creating a custom control with markup like this:
<Custom:CustomGrid>
<Columns>
<Custom:DataColumn HeaderText="FirstName" />
<Custom:DataColumn HeaderText="LastName" />
</Columns>
</Custom:CustomGrid>
I am overriding both Render and RenderChildren in order to render the outer Div/Table and Column tags respectively.
I want each of the THs to include a LinkButton, with the HeaderText for sorting. I created a foreach loop to run over the collection of columns and create a TH for each with a LinkButton inside it. I render out the LinkButton using linkBtn.RenderControl(writer);
What I get in html is just an empty anchor tag.
I’m guessing this is due to the fact that asp.net does not know to render the JS side of the server control when it is rendered this way.
But I have no idea what I can do differently.
Any ideas?
EDIT: I can see that href=”javascript:_doPostBack('myGrid$Sort_firstName','')”
is created. I don’t know why the characters are html escaped, but I’m guessing it’s just the html source viewer (or maybe not…) Anyway, the event handler is still not being fired.
Turns out that CreateChildControls is not the place to create child controls… (Who would of thunk it…)
I moved the code adding the controls to the Controls colletion to OnInit and everything was wiered up correctly.
Turns out that CreateChildControls is called too late in the lifecycle for the post back to route the events correctly.