0
    Department<br />
<asp:DropDownList ID="DeptDrop_1" runat="server" 
    DataSourceID="SqlDataSource_VMFG1" DataTextField="ID" DataValueField="ID">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource_VMFG1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:VMFGConnectionString %>" 
    SelectCommand="SELECT [ID] FROM [DEPARTMENT]"></asp:SqlDataSource>

New at this, so be gentle. Basically what I'm trying to do is get the form to load a list of possible departments for a given employee directly from our ERP database- so I can be sure it's up-to-date.

Visually the dropbox seems to work, it pulls the desired column and makes the choices available in the form.

But the real endgame here is to get the form contents to post to a text file, and for whatever reason (probably how I declared it in the code-behind) it won't post the content of the dropbox to the container file.

It just leaves a blank.

Here's the codebehind (it's been suggested I post more of it- apologies if much of it ins't relavent):

        Protected Sub SUBMIT_1_Click(sender As Object, e As EventArgs) Handles SUBMIT_1.Click
    Dim Message As String = ""
    Dim Emp_Name As String = ""
    Dim Emp_ID As String = ""
    Dim DTPick_TI As String = ""
    Dim DTPick_TO As String = ""
    Dim TypeDropList1 As String = ""
    Dim Department As String = ""
    Dim LdmSup_1 As String = ""
    Dim AdjReason_1 As String = ""

    Department = DeptDrop_1.SelectedItem.Value

    Dim fso
    Dim tst

    fso = Server.CreateObject("Scripting.FileSystemObject")
    tst = fso.OpenTextFile("C:\Users\01853\Documents\Visual Studio 2010\Projects\IntranetForms2\IntranetForms2\Output\reading.txt", 2)

    tst.writeline("Emp_Name = " & Request.Form("Emp_Name"))
    tst.writeline("Emp_ID = " & Request.Form("Emp_ID"))
    tst.writeline("Time_In = " & Request.Form("DTPick_TI"))
    tst.writeline("Time_Out = " & Request.Form("DTPick_TO"))
    tst.writeline("Type of Correction = " & Request.Form("TypeDropList1"))
    tst.writeline("Department = " & Request.Form("Department"))
    tst.writeline("Leadman/Supervisor = " & Request.Form("LdmSup_1"))
    tst.writeline("Reason/Comment = " & Request.Form("AdjReason_1"))

    tst.close()
    tst = Nothing
    fso = Nothing

    Message = "Your Clock Adjustment Request has been sent to Human Resources.  Thank you."

    Notify_1.Text = Message

End Sub

This is probably a pretty obvious answer, but I'm having an issue finding an answer at all (likely I don't know enough of the lingo to search effectively).

  • You will likely need to include additional code for us to be able to help, however, without more to go on, try looking to ensure that when your your page load is called on PostBack you aren't resetting your dropdownlist. – G_P Jul 10 '18 at 18:08
  • Really not sure what you mean. I'm only sort of familiar with the term "PostBack" as it relates to this. Some quick poking at the term reveals it's a sort of intermediary step between Submit and the final result (in my case, writing to a text file). How would I know if something is being reset during this process? Assume I wouldn't have done so deliberately- mostly because I don't know how. And I guess I can cram the whole code in here, but that feels like hitting a fly with a sledgehammer... – SkunkWerks7 Jul 10 '18 at 18:13
  • Yes, when you have a form with a submit button, and the submit button is clicked, the form values are posted back to the server. In asp.net webforms, the page load method fires both on the initial page load *and* upon this postback. So if you are doing page initialization in that page load method, it's import to check for that scenario. More info here: https://stackoverflow.com/questions/3620883/implementation-of-ispostback-in-page-load – G_P Jul 10 '18 at 18:17
  • If you debug this code, what is the value of Department after this line? Department = DeptDrop_1.SelectedItem.Value If that has a value, you can just use Department in your writeline call, rather than Request.Form("Department") – G_P Jul 10 '18 at 18:23
  • Chronologically speaking- whatever is happening during page load should be irrelevant to what I'm attempting to accomplish (and not accomplishing) in this context- I'd think. I'd just like the form to take whatever has been selected in the drop box and write that line to the text file. All the other fields write- including the custom droplist (which isn't SQL-derived). Conspicuously the only one that seems to refuse to write is the SQL-derived droplist. I'm assuming there's some minor detail I'm missing here- something different about that input type. – SkunkWerks7 Jul 10 '18 at 18:25
  • well, I was guessing at that point since the additional code wasn't yet posted, and what I mentioned is a common issue for beginners in webforms. However, debug your app, and do a quick watch on the Request.Form object, and look at it's values. The code you posted is doing this: Request.Form("Department") but that value should likely be Request.Form("DeptDrop_1") – G_P Jul 10 '18 at 18:28
  • Just taught myself how to do a debug/quickwatch. According to that the response is "Unable to evaluate the expression." Unfortunately as analytical as I can get about that amounts to "that sounds bad." – SkunkWerks7 Jul 10 '18 at 18:44

1 Answers1

0

Hi you need to read the value of the dropdown if you are usign a dropdownlist object, like this

DropDownList1.SelectedItem.Text 

or

DropDownList1.SelectedItem.Value

To store the file you will need a share location and use a unc path, you won't have that location in the server where you install the application.

Juan
  • 1,352
  • 13
  • 20
  • Not worried about the pathing at the moment. Never built a webform before and so I'm just testing the output. I'll finalize it later. I do have the `DropDownList1.SelectedItem.Value` line in there, though I'm not confident I'm using it correctly here, for obvious reasons. – SkunkWerks7 Jul 10 '18 at 18:37
  • In web forms you dont use request.form you use the id of the element and then a property to read the value, if is a textbox then use text. – Juan Jul 10 '18 at 19:02
  • Doesn't seem to make a difference whether I use 'text' or 'value'. The result is the same. – SkunkWerks7 Jul 10 '18 at 19:05