A
Al Smith
Newbee to aspx needs direction.
We are using an <INPUT type="file" tag to upload a file. We also have a
text field for the user to enter a description for the file which the user
must enter. Server side validation was being done for the description field
having length and if not an appropriate message was written back to the
client. However, in the process, the filename the user enters is not
persisted between server calls (HTMLInputFile control). Also after some
research I found where the "value" property for the <INPUT type="file" tag
is read only for security purposes. Soo, I thought I would just do client
side validation to make sure the description field was filled in. Now my
problem is how to raise the appropriate event back on the server. The code
below shows my issue.
The original code. When clicked, the btnUpload_Click event on the server is
raised and the description field being filled in was validated. If not
filled in, the user supplied value of the <INPUT type="file" is lost back on
the client.
<INPUT type="file" id="File1" NAME="File1" size="35" class="txt"
runat="server">
<INPUT class="txt" type="text" size="35" id="DocName" name="DocName"
maxlength="50" runat="server">
<input type="button" id="btnUpload" class="btn" value="Upload"
OnServerClick="btnUpload_Click" NAME="btnUpload" runat="server">
Soo, I changed the btnUpload to call JS on the client as shown next.
<INPUT type="file" id="File1" NAME="File1" size="35" class="txt"
runat="server">
<INPUT class="txt" type="text" size="35" id="DocName" name="DocName"
maxlength="50" runat="server">
<input type="button" id="btnUpload" class="btn" value="Upload"
OnClick="btnUpload_Click()" NAME="btnUpload">
and added the JS:
<script LANGUAGE="javascript" >
<!--
function btnUpload_Click(){
if ( Form1.DocName.value.length == 0 ){
alert("Fill in a description.");
}
else{
Form1.submit();
}
}
//
-->
</script>
What I do not know how to do is in the else. I don't want to just do a
"Form1.submit()", I would like to simulate the aspx way and effectively
raise the btnUpload_Click event on the server or some other server sub.
We are using an <INPUT type="file" tag to upload a file. We also have a
text field for the user to enter a description for the file which the user
must enter. Server side validation was being done for the description field
having length and if not an appropriate message was written back to the
client. However, in the process, the filename the user enters is not
persisted between server calls (HTMLInputFile control). Also after some
research I found where the "value" property for the <INPUT type="file" tag
is read only for security purposes. Soo, I thought I would just do client
side validation to make sure the description field was filled in. Now my
problem is how to raise the appropriate event back on the server. The code
below shows my issue.
The original code. When clicked, the btnUpload_Click event on the server is
raised and the description field being filled in was validated. If not
filled in, the user supplied value of the <INPUT type="file" is lost back on
the client.
<INPUT type="file" id="File1" NAME="File1" size="35" class="txt"
runat="server">
<INPUT class="txt" type="text" size="35" id="DocName" name="DocName"
maxlength="50" runat="server">
<input type="button" id="btnUpload" class="btn" value="Upload"
OnServerClick="btnUpload_Click" NAME="btnUpload" runat="server">
Soo, I changed the btnUpload to call JS on the client as shown next.
<INPUT type="file" id="File1" NAME="File1" size="35" class="txt"
runat="server">
<INPUT class="txt" type="text" size="35" id="DocName" name="DocName"
maxlength="50" runat="server">
<input type="button" id="btnUpload" class="btn" value="Upload"
OnClick="btnUpload_Click()" NAME="btnUpload">
and added the JS:
<script LANGUAGE="javascript" >
<!--
function btnUpload_Click(){
if ( Form1.DocName.value.length == 0 ){
alert("Fill in a description.");
}
else{
Form1.submit();
}
}
//
-->
</script>
What I do not know how to do is in the else. I don't want to just do a
"Form1.submit()", I would like to simulate the aspx way and effectively
raise the btnUpload_Click event on the server or some other server sub.