开发者

Create FileUpload from code behind

I need to create a FileUpload control from the code behind page. I have this function:

Private Function CreateUpload() As FileUpload

Dim txtFileUpload As New FileUpload
txtFileUpload.ID = "element1"
Return txtFileUpload

End Function

However, even though I successfully use a similar technique for other form controls, my FormUpload开发者_开发问答 doesn't get rendered to the page.

Can someone please explain what I'm doing wrong.

Edit: I'm writing the returned FileUpload to a DIV on the page outside of my function.

Update: It's sorted. Seemed to be a problem with Visual Studio. Closing it, relaunching and then rebuilding the website sorted it. Thanks to all who responded.

Thanks.


I can't see you adding this control to the WebForm. Try adding it:

Private Function CreateUpload() As FileUpload

    Dim txtFileUpload As New FileUpload
    txtFileUpload.ID = "element1"
    Page.Controls.Add(txtFileUpload)
    Return txtFileUpload

End Function

or if you don't have access to the Page inside this function add it when you call the function in the code behind of your webform:

Dim txtFileUpload As FileUpload = CreateUpload()
Page.Controls.Add(txtFileUpload)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜