How to set a dynamic value for MaxFileSize

Feb 11, 2009 at 9:33 AM
Hi,

Tried to set the MaxFileSize from CodeBehind on Page_Load:
If Not IsPostBack Then
    ' get MaxFileSize from db
    FileUploader1.MaxFileSize = getMaxFileSizeAllowed()
End If

The MaxFileSize attribute is not updated. It remains with the default value.

Tried also to embed code block in ASP.NET like:
<fjx:FileUploader ID="FileUploader1" runat="server" MaxFileSize="<%=GetMaxFileSizeAllowed()%>"></fjx:FileUploader>

Where the function getMaxFileSizeAllowed() is defined on the ASP.NET page between <script runat="server"> tags. This caused a 'System.ApplicationException: There is a problem when trying to parse the file size'. Actually, this error is derived from the <%=[whatever]%> or <% Response.Write("whatever") %> code embedding.

How can I set a dynamic value for the MaxFileSize attribute?

Thanks!

Coordinator
Feb 11, 2009 at 9:49 AM
If getMaxFileSizeAllowed returns numeric value bytes then use it as 

If Not IsPostBack Then
    ' get MaxFileSize from db
    FileUploader1.MaxFileSize = getMaxFileSizeAllowed() & " bytes"
End If
Coordinator
Feb 11, 2009 at 9:51 AM
Edited Feb 11, 2009 at 9:52 AM
And of cource you cannot pass value like that to .NET control

<fjx:FileUploader ID="FileUploader1" runat="server" MaxFileSize="<%=GetMaxFileSizeAllowed()%>"></fjx:FileUploader>

You can pass it like that

<fjx:FileUploader ID="FileUploader1" runat="server" MaxFileSize='<%#GetMaxFileSizeAllowed()&"bytes"%>'></fjx:FileUploader>

But you also need to call FileUploader1.DataBind() method
Feb 11, 2009 at 10:28 AM
Thanks for the quick replies!
The uploader is placed on a usercontrol as part of a tabbed page. When I call getMaxFileSizeAllowed function outside 'If Not IsPostBack' (inside Page_Load), it solved the problem. The value is now updated dynamically from db.

Thanks again. Great control!