How to read input value from the Request.Form collection by input name

十年热恋 提交于 2019-12-24 13:22:41

问题


I want to be able to read values of HtmlHiddenField controls from the Request.Form collection in a user control on postback. The keys in the collection seem to represent the control's name attribute rather than ID. I can control the ID using the new ClientIDMode property which helps when my user control is placed in different pages thus within different naming containers. But how can I do the same with the name attribute? The HtmlHiddenField.Name property doesn't match the key name in Reqest[key] object when in a naming control.

I understand this is quite specific scenario because I don't have access to the hidden field control object. I am just looking for a way to control how the input name attribute is rendered as is now possible for IDs.


回答1:


You will have to access the value of the hidden field using the unique id property of the control like below

var postedValue = Request.Forms[hdnField.UniqueId];


来源:https://stackoverflow.com/questions/7723936/how-to-read-input-value-from-the-request-form-collection-by-input-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!