ASP。Net表单的字段仅在客户的env上为空

时间:2022-04-25 15:49:27

I was given a task to solve a bug on some old project that someone else wrote.
The project is ASP.Net deployed on IIS.

我被分配了一项任务,要解决别人写的某个旧项目的一个bug。这个项目是ASP。网络部署在IIS。

Scenario:

场景:

  1. Open Request form.
  2. 打开申请表。
  3. Fill personal details.
  4. 填写个人信息。
  5. Click button "Add Items" to open items selection window.
  6. 点击“添加项目”按钮打开项目选择窗口。
  7. Select items and close the item selection windows.
  8. 选择项并关闭项选择窗口。

Expected: Back in Request form, it is now showing both the personal details, entered in step 2 and now, on the same request page, the list of selected items, selected in step 4.

期望:回到请求表单,它现在显示了步骤2中输入的个人详细信息,现在,在同一个请求页面上,显示了步骤4中选择的项目列表。

Actual: Back in request form, not showing personal details and only showing the selected items.

实际:返回请求表单,不显示个人信息,只显示所选项目。


From the code I learn that every field on the request form is:

从代码中我了解到,请求表单上的每个字段是:

  1. Saved to the session (E.g onChange in JavaScript call code-behind save function)
  2. 保存到会话(E。g onChange在JavaScript调用代码后保存函数)
  3. Load from the session on Page_Load
  4. 在Page_Load从会话中加载

I guess the above is needed as a replacment machanism for the ViewState, because in the above scenario it is required for the form fields (E.g personal details) to persist across several pages. (The opening of other windows to add items...)

我想上面的内容可以作为ViewState的替换机制,因为在上面的场景中,表单字段(E)是必需的。g个人细节)保持在几页之间。(打开其他窗口添加项目…)

Also from the code I learn that items added on "Add Items" windows are:

我还从代码中了解到,添加在“添加项”窗口的项是:

  1. Saved to the session in the page "Add Items"
  2. 保存到“添加项”页面中的会话
  3. Loaded from the session in the Page_Load of page "Request"
  4. 在“请求”页面的Page_Load中从会话中加载

Now instead of working on the project over at the customer's offices we copied the project and deployed it back in our offices - only problem is now it is working fine - that is, both the personal details and the list of selected items are showing as expected.

现在,我们没有在客户的办公室进行项目工作,而是复制了项目并将其部署回我们的办公室——唯一的问题是它现在运行得很好——也就是说,个人细节和所选项目的列表都如预期的那样显示。

I would like any suggestions... What could be the cause of such behavior?
Also in case I will not be able to recreate the problem on my environment, what should I check/debug on the customer's office?

我想要一些建议……这种行为的原因是什么?另外,如果我无法在我的环境中重新创建问题,我应该在客户的办公室中检查/调试什么?

1 个解决方案

#1


1  

...What could be the cause of such behavior?

…这种行为的原因是什么?

Based on your symptoms, it sounds like could be happening is the server is relying on a client-side script (to set the form values sent down from the server's response) that has a dependency (e.g. jQuery) that might not be supported by the (possibly outdated) browser being used.

根据您的症状,可能发生的情况是,服务器依赖于客户端脚本(用于设置从服务器响应发送的表单值),该脚本具有可能不受正在使用的(可能过时的)浏览器支持的依赖项(例如jQuery)。

...what should I check/debug on the customer's office?

…我应该在客户的办公室检查/调试什么?

Here is what I gather is supposed to be happening after the client has the form open:

以下是在客户打开表格后应该发生的事情:

  1. User enters values in form control(s). ("Personal Details")
  2. 用户在表单控件中输入值。(“个人资料”)
  3. Client-side event handler sends asychronous requests to the server (no callback) in order to save form values to the user's Session.
  4. 客户端事件处理程序将同步请求发送到服务器(没有回调),以便将表单值保存到用户会话。
  5. User clicks a button. ("Add Items")
  6. 用户点击一个按钮。(“添加项目”)
  7. Client-side event handler opens a new window that sends a request to the server for the "Items Selection" page.
  8. 客户端事件处理程序打开一个新窗口,该窗口向服务器发送“Items Selection”页面的请求。
  9. Response is received from the server and the "Items Selection" page is displayed on the client.
  10. 从服务器接收响应并在客户机上显示“项目选择”页面。
  11. User selects values for controls. ("Items Selection")
  12. 用户为控件选择值。(“选择项目”)
  13. User clicks a button ("Close Window")
  14. 用户点击按钮(“关闭窗口”)
  15. Client-side event handler:
    • Sends a request (with the "Items Selection" values) on behalf of the previous window to the server for the "Personal Details" page.
    • 代表前一个窗口向服务器发送一个请求(带有“项目选择”值)以获取“个人详细信息”页面。
    • Closes the current window.
    • 关闭当前窗口。
  16. 客户端事件处理程序:代表上一个窗口向服务器发送一个请求(带有“项目选择”值)以获取“个人详细信息”页面。关闭当前窗口。
  17. Previous window receives response, page reloads completely, and all form data is still present (reloaded).
  18. 以前的窗口接收响应,页面完全重新加载,所有表单数据仍然存在(重新加载)。

We know at the very least 9. isn't actually happening properly, since this is your stated problem.

我们至少知道9个。这并不是正确的,因为这是你的问题。

Assuming I have your implementation correct, you should start by determining how the values are supposed to be written to the controls during the last step (e.g. server controls' values assigned directly or server registers start-up client-script to write the form values). Then you should check the values that are sent to the method you discovered. If the values are incorrect, keep backing up to each previous server request to see what is the resulting Session state before the response. If the values are correct then you know something is going wrong (most-likely client-side) after the client receives the response from the server (I think this should only happen if my jQuery theory above is correct).

假设您的实现是正确的,您应该首先确定在最后一步中应该如何将值写入控件(例如,服务器控件直接分配的值或服务器注册启动客户端脚本以编写表单值)。然后,您应该检查发送到您发现的方法的值。如果值不正确,请继续备份以前的每个服务器请求,以查看响应前的结果会话状态。如果值是正确的,那么在客户端收到来自服务器的响应之后(我认为只有在我上面的jQuery理论是正确的情况下才会发生),您才会知道出了问题(最可能的客户端)。

#1


1  

...What could be the cause of such behavior?

…这种行为的原因是什么?

Based on your symptoms, it sounds like could be happening is the server is relying on a client-side script (to set the form values sent down from the server's response) that has a dependency (e.g. jQuery) that might not be supported by the (possibly outdated) browser being used.

根据您的症状,可能发生的情况是,服务器依赖于客户端脚本(用于设置从服务器响应发送的表单值),该脚本具有可能不受正在使用的(可能过时的)浏览器支持的依赖项(例如jQuery)。

...what should I check/debug on the customer's office?

…我应该在客户的办公室检查/调试什么?

Here is what I gather is supposed to be happening after the client has the form open:

以下是在客户打开表格后应该发生的事情:

  1. User enters values in form control(s). ("Personal Details")
  2. 用户在表单控件中输入值。(“个人资料”)
  3. Client-side event handler sends asychronous requests to the server (no callback) in order to save form values to the user's Session.
  4. 客户端事件处理程序将同步请求发送到服务器(没有回调),以便将表单值保存到用户会话。
  5. User clicks a button. ("Add Items")
  6. 用户点击一个按钮。(“添加项目”)
  7. Client-side event handler opens a new window that sends a request to the server for the "Items Selection" page.
  8. 客户端事件处理程序打开一个新窗口,该窗口向服务器发送“Items Selection”页面的请求。
  9. Response is received from the server and the "Items Selection" page is displayed on the client.
  10. 从服务器接收响应并在客户机上显示“项目选择”页面。
  11. User selects values for controls. ("Items Selection")
  12. 用户为控件选择值。(“选择项目”)
  13. User clicks a button ("Close Window")
  14. 用户点击按钮(“关闭窗口”)
  15. Client-side event handler:
    • Sends a request (with the "Items Selection" values) on behalf of the previous window to the server for the "Personal Details" page.
    • 代表前一个窗口向服务器发送一个请求(带有“项目选择”值)以获取“个人详细信息”页面。
    • Closes the current window.
    • 关闭当前窗口。
  16. 客户端事件处理程序:代表上一个窗口向服务器发送一个请求(带有“项目选择”值)以获取“个人详细信息”页面。关闭当前窗口。
  17. Previous window receives response, page reloads completely, and all form data is still present (reloaded).
  18. 以前的窗口接收响应,页面完全重新加载,所有表单数据仍然存在(重新加载)。

We know at the very least 9. isn't actually happening properly, since this is your stated problem.

我们至少知道9个。这并不是正确的,因为这是你的问题。

Assuming I have your implementation correct, you should start by determining how the values are supposed to be written to the controls during the last step (e.g. server controls' values assigned directly or server registers start-up client-script to write the form values). Then you should check the values that are sent to the method you discovered. If the values are incorrect, keep backing up to each previous server request to see what is the resulting Session state before the response. If the values are correct then you know something is going wrong (most-likely client-side) after the client receives the response from the server (I think this should only happen if my jQuery theory above is correct).

假设您的实现是正确的,您应该首先确定在最后一步中应该如何将值写入控件(例如,服务器控件直接分配的值或服务器注册启动客户端脚本以编写表单值)。然后,您应该检查发送到您发现的方法的值。如果值不正确,请继续备份以前的每个服务器请求,以查看响应前的结果会话状态。如果值是正确的,那么在客户端收到来自服务器的响应之后(我认为只有在我上面的jQuery理论是正确的情况下才会发生),您才会知道出了问题(最可能的客户端)。