Asp.net获取HTML输入框的内容

时间:2015-06-01 19:37:59

标签: c# html asp.net

我试图将接受的答案应用于此问题How to access html form input from asp.net code behind

和其他类似问题。

我有以下HTML输入,用于显示日期选择器:

FROM:<input type="text" runat="server" name="popupDatepickerFrom" id="popupDatepickerFrom">

然后此代码检索值:

    string myStringFromTheInput = popupDatepickerFrom.Value;
    Response.Write(myStringFromTheInput);
    Response.End();

但这不会返回任何东西。我做错了什么?

3 个答案:

答案 0 :(得分:2)

确保您的输入位于表单元素中,如本页所示:

How to access html form input from asp.net code behind

答案 1 :(得分:1)

尝试

string text = " ( ((abc ) def)ghi)";

text = text.Replace("(","( ").Replace(")"," )");//Add aditional space no matter if this one already have it.

while(text.Contains("  ")){//===>To while text contains double spaces
  text = text.Replace("  "," ");//===>Replace spaces for a single space;
}

答案 2 :(得分:1)

您应该可以从以下数据访问popupDatepicker:

string myStringFromTheInput = String.Format("{0}", Request.Form["popupDatepickerFrom"]);
Response.Write(myStringFromTheInput);
Response.End();