so I have a slight issue with doing 2 things on a web page. I’m using a to upload a file to my web server, at the same time I have other used to get data from the user (first name, last name ect) The form is runat=server, the button that is supposed to upload the file (after some preliminary checking that the file is ok, and that the forms fields are filled out properly) is also runat server, with a onserver click.
The main issue is that, when I give the form a “get” method, I can get the desired result of having all my data in the url where I want it, but then I can’t upload a file. While if I remove that tag, I can upload a file, but then I get no data in my url.
(Relevant code)
<script language="VB" runat="server">
Dim str As String
Sub Button1_Click(ByVal Source As Object, ByVal e As EventArgs)
'Dim submitFunction As String = "<script type='text/javascript'> function submitform() { document.myform.submit();}" & "</" & "script>"
Session("firstTime") = 4
Session("errCheck") = 1
If InputF.Value = "" Then
Span1.InnerHtml = "Error: you must enter a file name"
Return
End If
If Not (InputF.PostedFile Is Nothing) Then
Try
If Session("firstTime") <> 1 Then
If Request.QueryString("fName") = "" Then
str += "Please Enter your first name <br/>"
Session("errCheck") += 1
End If
If Request.QueryString("lName") = "" Then
str += "Please Enter your last name <br />"
Session("errCheck") += 1
End If
If Request.QueryString("addr1") = "" Then
str += "Please Enter your address <br />"
Session("errCheck") += 1
End If
If Request.QueryString("city") = "" Then
str += "Please Enter a city name <br />"
Session("errCheck") += 1
End If
If Len(Request.QueryString("prov")) <> 2 Then
str += "Please Enter a 2 character province <br />"
Session("errCheck") += 1
End If
If Len(Request.QueryString("pCode")) <> 6 Then
str += "Please Enter a valid postal code <br />"
Session("errCheck") += 1
End If
If Request.QueryString("hPhone") = "" Then
str += "Please Enter your home phone <br />"
Session("errCheck") += 1
ElseIf Len(Request.QueryString("hPhone")) <> 10 Then
str += "Please enter a 10 digit number for your home phone <br />"
Session("errCheck") += 1
End If
End If
If Session("errCheck") = 1 Then
InputF.PostedFile.SaveAs(("FILE PATH TO MY SERVER" & Request.QueryString("compName") & " - " & Request.QueryString("fName") & ", " & Request.QueryString("lName") & InputF.Value))
'Response.Redirect("default.aspx?fName=" & Request.QueryString("fName"))
End If
Catch exc As Exception
str += "Error Saving File"
Span1.InnerHtml = "Error saving file"
Session("errCheck") += 1
End Try
End If
End Sub 'Button1_Click
</script>
<form name="myform" id="myform" method="get" runat="server" enctype="multipart/form-data">
<table>
<h2><% If Session("errCheck") <> 1 Then
Response.Write(Str)
End If%></h2>
<tr>
<td align="right"><label>Resume/Documents</label></td>
<td><input type="file" runat="server" id="InputF" name="InputF" onchange="handleFiles(this.files)" /><input type="button" id="adder" value="add another document" onclick="addInput('dynamicInput');" /></td>
<div id="dynamicInput">
</div>
</tr>
<tr>
<td>
<span id=Span1
style="font: 8pt verdana;"
runat="server" />
</td>
</tr>
<input type="hidden" id="Hidden13" name="compName" value="<% response.Write(request.QueryString("compName")) %>" />
<input type="hidden" id="posCode" name="posCode" value="<% response.Write(request.QueryString("posCode"))%>" />
<input type="hidden" id="reqNum" name="reqNum" value="<% response.Write(request.QueryString("reqNum")) %>" />
<input type="hidden" id="company" name="company" value="<% response.Write(request.QueryString("company"))%>" />
<input type="hidden" id="division" name="division" value="<% response.Write(request.QueryString("division")) %>" />
<input type="hidden" id="department" name="department" value="<% response.Write(request.QueryString("department"))%>" />
<tr>
<td align="right">First name<span style="color:Red;">*</span>:</td>
<td><input type='text' name='fName' id='fName' size='50' maxlength="50"value="<% Response.Write(Request.QueryString("fName"))%>" /></td>
</tr>
<tr>
<td align="right"><label>Last name </label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='lName' id='lName' size='50' maxlength="50" value="<% response.Write(request.QueryString("lName"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Initial</label>:</td>
<td><input type='text' name='init' id='init' size='2' maxlength="2" value="<% response.Write(request.QueryString("init"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Email</label>:</td>
<td><input type='text' name='email' id='email' size='50' maxlength="50" value="<% response.Write(request.QueryString("email"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Address 1</label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='addr1' id='addr1' size='25' maxlength="25" value="<% response.Write(request.QueryString("addr1"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Address 2</label>:</td>
<td><input type='text' name='addr2' id='addr2' size='25' maxlength="25" value="<% response.Write(request.QueryString("addr2"))%>"/></td>
</tr>
<tr>
<td align="right"><label>City</label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='city' id='city' size='25' maxlength="25" value="<% response.Write(request.QueryString("city"))%>"/></td>
</tr>
<br />
<tr>
<td align="right"><label>Province</label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='prov' id='prov' size='2' maxlength="2" value="<% response.Write(request.QueryString("prov"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Country</label>:</td>
<td><input type='text' name='count' id='count' size='25' maxlength="25" value="<% response.Write(request.QueryString("count"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Postal code</label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='pCode' id='pCode' size='25' maxlength="25" value="<% response.Write(request.QueryString("pCode"))%>"/></td>
</tr>
<tr>
<td align="right"><label>Home Phone</label><span style="color:Red;">*</span>:</td>
<td><input type='text' name='hPhone' id='hPhone' size='15' maxlength="15" value="<% response.Write(request.QueryString("hPhone"))%>"/></td>
<p>Format for phone numbers: Areacode, phone number, no spaces, no dashes ie: 2041231234</P>
</tr>
<tr>
<td align="right"><label>Work Phone</label>:</td>
<td><input type='text' name='wPhone' id='wPhone' size='25' maxlength="25" value="<% response.Write(request.QueryString("wPhone"))%>"/></td>
</tr>
</table>
<input type=button
id="Button1"
value="Submit Application"
OnServerClick="Button1_Click"
runat="server" />
</form>
I was close to getting this myself. On form submit, I do all the validation for the other files, then if all checks out, I submit the form to a different page(with other non-relevant code).
Basically the code I posted is good, I was just missing a few things for when it’s submitted
In short:
Hopefully that makes sense to anyone looking at my question and now my answer.