本文介绍了输入控制型Text参考在code的背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code

 <输入=服务器ID =名称TYPE =文本名称=名称/>
    cmd.parameters.addwithvalue(@ NAME,Name.value);

我试图捕捉到我我的控制和(Name.value)内输入数据总是等于
不管是什么I型。我知道他们是正确的映射,如果我切换到一个文本框,它工作正常,我希望得到这个输入的工作为好。

EDITED
这似乎工作,不知道这是做正确的方法,但任何理由为什么这会工作,但Name.value不?

  cmd.Parameters.AddWithValue(@ NAME的Request.Form [名称]);


解决方案

如果你想使用HTML元素在code的背后,你必须添加 RUNAT =服务器属性。

 <输入=服务器ID =名称TYPE =文本名称=名称的ClientIDMode =静态/>

设置的ClientIDMode 静态应允许您使用相同的ID后面的code在html,只是要小心,不要制造矛盾。

名称将被转换为 HtmlInputControl ,并在页面回, Name.Value 将有与已输入的文本输入的值。所以,那么你可以这样做:

  cmd.Parameters.AddWithValue(parameterename,Name.Value);

I have the following code

  <input runat="server" id="Name" type="text" name="Name"/>


    cmd.parameters.addwithvalue("@NAME", Name.value);

I am trying to capture the data I enter inside my control and (Name.value) always equals ""No matter what I type. I know they are mapped correctly as if I switch it to a textbox it works fine I would like to get this input working as well.

EDITED This seems to work not sure if this is the proper way to do this but any reason why this would work but Name.value does not?

cmd.Parameters.AddWithValue("@NAME", Request.Form["Name]);
解决方案

If you want to use html elements in a code behind you have to add the runat=server attribute.

<input runat="server" id="Name" type="text" name="Name" ClientIdMode="static"/>

Setting the ClientIdMode to static should allow you to use the same id in the code behind as in the html, just be careful not to create conflicts.

Name will be cast as an HtmlInputControl, and when the page posts back, Name.Value will have the value of the input with the text that was entered. So then you can do:

cmd.Parameters.AddWithValue("parameterename", Name.Value);

这篇关于输入控制型Text参考在code的背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 08:04