获取表单字段名称上提交表单时,由用户控制 [英] Getting form field names on Submit when form is user control

查看:135
本文介绍了获取表单字段名称上提交表单时,由用户控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我慢慢地,一点一点地学习什么,我用ASP.NET做

I am slowly, piece by piece learning what I am doing with ASP.NET

我已经建立了我的新的Web应用程序的开始,但我经常来面对的ASP.NET重命名元素ID或表单域,其名称的大小写问题。

I've created the beginnings of my new web application, but I am often coming up against the issue that ASP.NET renames elements IDs or in the case of form fields, their names.

我有一个形式,它基本上是一个销售体系。它本质上是由两个用户控件,一个是客户详细信息(姓名,地址等),第二个形式为客户的采购形式,它包含动态地使用Javascript创建造就了一批线路为你列出的项目该客户购买。

I have a form which is basically a sales system. It is essentially made up of two User Controls, one is a form for Customer Details (name, address etc) and the second is a form for the customer's purchases, it consists of a number lines dynamically created by Javascript created as you list the items the customer is purchasing.

这两个部分是用户控制,因为它们将被用于系统,其中该数据需要被召回/重新输入的其他区域。

Both these sections are User Controls because they are to be used for other areas of the system where this data will need to be recalled/re-entered.

在加载用户控件,其中包含客户的名称字段重命名M $日程地址搜索Maincontent $ customerForm $名为我明白的地方这是来自 M是我的母版页的ID,日程地址搜索Maincontent的主要内容占位符和customerForm是用户控件的名称。

When the USer Control is loaded, the field which contains the Customers' Name is renamed "m$mainContent$customerForm$name" I understand where this comes from, "m" is the ID of my Master Page, "mainContent" is the main Content Placeholder and "customerForm" is the name of the User Control.

其实,于我而言,这将永远保持不变的所有形式,所以它是相对容易克服...但是...想这不是

In fact, in my case, this will always remain the same on all forms, so it is relative easy to overcome... but... suppose it wasn't

我可以看到有办法,我可以处理这个使用Javascript,但形式并不需要AJAX提交,正常的邮政将做精本,所以当我打开网页recieving我想打电话给的Request.Form(名称)%客户的名称保存到数据库中,但当然我真的需要的Request.Form(M $日程地址搜索Maincontent $ customerForm $名)%

I can see there are ways I could deal with this with Javascript, but the form doesn't need an AJAX submit, a normal Post will do fine for this, so when I open up the recieving page I want to call Request.Form("name")% to save the customer's name into the database, but of course I really need Request.Form("m$mainContent$customerForm$name")%

我将如何动态地从张贴表单中提取的prefixes确保如果我重命名任何东西,或在不同的场景中使用它,问题不会打破它?

How would I dynamically extract those prefixes from the posting form to ensure that if I rename anything or use it in a different scenario, the problem will not break it?

我使用.NET 2.0,所以不能用静态客户端。

I am using .NET 2.0, so can't use Static Client.

推荐答案

这是真的老了,但让我们看看它是否对您有用。

This is really old but let's see if it's useful for you.

例如的我设法从给定的值字段名没有preFIX。

Getting this example I managed to get the value from a given field name without prefix.

我敢肯定它是不是最好的解决办法,但对我来说是有益的。比方说,你要恢复一个名为hfIdAviso字段的值,则在POST作为ctl00 $ $身体hfIdAviso

I'm sure it is not the best solution, but it was useful for me. Let's say you want to recover the value of a field named "hfIdAviso", that comes in the POST as "ctl00$body$hfIdAviso":

var value = Request.Form.Cast<string>()
                    .Where(key => key.EndsWith("hfIdAviso"))
                    .ToDictionary(key => key, key => Request.Form[key])
                    .Values.FirstOrDefault();

这将返回值该字段。

希望它帮助。

这篇关于获取表单字段名称上提交表单时,由用户控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆