0

I am adding a check to verify the size of the file imported in my web application. If the file size is greater than 4 MB i need to show a confirmation pop, whether a user is sure to upload the file. If user selects yes the default functionality occurs else upload is cancelled.

I am trying to open a confirmation pop up from server side using

Page.ClientScript.RegisterStartupScript(typeof(NewDocument), "ValidateFileSize",    "<script>ValidateFileSize()</script>");

Where ValidateFileSize() is a JavaScript function that shows the confirmation box.

But the problem is, the control of the page at server side moves ahead before I set the result of the confirmation pop up using hidden variable and use it in 'if-else' condition. Therefore, i am unable to read the value of the hidden variable and skipping the uploading code at server side. I am using the concept of hidden variable as in javascript element.files.size does not work in IE8.

Could anyone suggest a better approach or solution to this. Or the only solution is using .aspx page as a popup?

Alexander Rühl
  • 6,769
  • 9
  • 53
  • 96
user3725094
  • 65
  • 10

2 Answers2

0

first of all your question is not clear, i hope your requirement is to check file size at client side. but you question indicating that you are looking for how to open popup in javascript.

any way, when comes to your question,

once control goes to server side then file upload control will be refreshed, so better check file size completely in javascript instead of calling script method from server side.

below are some urls for you reference.

Get file size before uploading

JavaScript file upload size validation

Applying javascript to check file size and extension

Community
  • 1
  • 1
  • pop up will come up, when the file size is greater than 4MB. In IE8 you cannot read file size using Javascript. If know how, please share a solution apart from ActiveXObject usage. – user3725094 Aug 01 '14 at 11:30
0

You can use a literal control and set its html to script.

e.g.

<asp:Literal ID="LiteralText" runat="server" Text=""></asp:Literal>

and then from your server side set the Text property as below

if(FILE SIZE IS > 4MB)
{
LiteralText.Text = "<script>ValidateFileSize()</script>";
}
else{
//UPLOAD FILE LOGIC HERE
}
Ronak Patel
  • 2,570
  • 17
  • 20