Dynamically created controls causing Null reference

后端 未结 5 1640
情深已故
情深已故 2021-01-07 15:26

I am trying to dynamically create controls and give them properties during run time.

I have put my code inside the Page_Init event, when I run my website I can see m

5条回答
  •  庸人自扰
    2021-01-07 15:55

    try to put your code in the Page_Load instead of Page_Init and also, check for null before using objects returned by FindControl.

    I suspect the object InputTextBox is null and it crashes when you try to print its Text.

    as a general rule just check for null and also for type when casting results of FindControl to something else.

提交回复
热议问题