Datalist Dynamic Template Loading Problem

M

mbailey

Hello-
I am failry new to asp.net but have been coding in general for a while.

I have a datalist whos templates are built on the fly.
In the Page_Init sub, based on a certain value, certain external
controls are assigned as the ItemTemplate and the EditTemplate.

1)If I only assign these templates if its not a post back, the datalist
is blank when I click on the edit button in the datalist.

2) If I let the page_init assign these templates everytime there is a
postback, the edit datalist renders correctly (a few drop downs and a
textbox).
But when I click my update button, I then try to a FindControl on my
datalist with a control I know is in the edit template but it gives me
this error:"Object reference not set to an instance of an object. "

Has anyone come across this?

Thanks in advanced!
MB
 
B

Brock Allen

1)If I only assign these templates if its not a post back, the
datalist is blank when I click on the edit button in the datalist.

You need to recreate any and all dynamic controls upon every postback. You
typically do this inside of CreateChildControls (a virtual from the Control
base class). If you recreate the controls properly, then it will behave as
if they were done statically in the ASPX file.
 
M

mbailey

Thanks Brock, I'll give it a shot.
I did not see your reply before I posted my previous reply.

Thanks Again
MB
 

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,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top