简体   繁体   English

我如何从Literall Control ASP NET获得价值

[英]How do i get a value from Literall Control ASP NET

I have a code for input i want to get the value of Literal Control dynamically. 我有一个输入代码,我想动态获取Literal Control的值。 How do i get the value of input I have selected? 如何获得所选的输入值?

Front Code 前台代码

<ul id="ulTest" runat="server"></ul>


Dim a As LiteralControl = New LiteralControl("<input type = ""date"" id=""start"" name=""trip-start"" value = ""2018-07-22"" min = ""2018-01-01"" max=""2018-12-31"">")
a.ID = "as"
ulTest.Controls.Add(a)

Dim tb As TextBox = (TextBox)a.FindControl("as")
ul1.Controls.Add(New LiteralControl(a.Text))

A literal control represents client-side markup that gets rendered out, and should have no expectation of being able to process posted data. 文字控件表示已被渲染的客户端标记,并且不应期望能够处理已发布的数据。 If you are writing a literal out that is a textbox, you can add that as a literal, but the only way to read the value from it is to use: 如果要编写的文字是文本框,则可以将其添加为文字,但是从中读取值的唯一方法是使用:

Request.Form("trip-start")

There will be no direct control representation other than to do: 除了执行以下操作外,没有其他直接控制表示形式:

foreach (var ctl in ulText.Controls)
{
    if (ctl is LiteralControl)
    {
       var a = (LiteralControl)ct;
       //Attempt to do something
     }
}

I don't believe that the value you entered will be posted back; 我认为您输入的值不会被回寄; it simply will be the original markup declaration. 它只是原始的标记声明。 Also, you can't cast this then as a textbox; 另外,您不能将其投射为文本框。 an error will occur: 将会发生错误:

var tb = (TextBox)a.FindControl("as"); //Throws Exception

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在这种情况下如何从asp.net的下拉控件中获取价值? - how to get value from dropdown control in asp.net in this scenario? 如何从ASP.NET中的DetailsView控件获取值? - How to get value from DetailsView Control in ASP.NET? 如何从适用于 IE 和 FireFox 的 asp.net 文件上传控件获取文件名? - How do i get the file name from an asp.net fileupload control that works in IE and FireFox? 如何在ASP.NET图表控件中获取此图表? - How do I get this chart in a ASP.NET chart control? 如何从ASP.NET MVC属性中获取枚举值? - How do I get an enum value from my ASP.NET MVC property? 我如何从 <select>在ASP.NET MVC中 - How do I get the text value from a <select> in ASP.NET MVC 如何将数据从Select2选项/值(标签)获取到ASP.NET MVC中的控制器? - How do I get the data from a Select2 options/value (tags) to the controller in asp.net mvc? 我需要从 ASP.NET 网络表单中的用户控件 HTML 创建 PDF 吗? 如何从用户控制中获取 html,然后将 HTML 转换为 PDF? - I need to create PDF from user control HTML in ASP.NET webforms ? How do i get html from user control and then convert that HTML to PDF? 如何有条件地控制ASP.NET中控件的可见性? - How do I conditionally control the visibility of a control in ASP.NET? 如何从 ASP.NET 用户控件中的父页面访问控件? - How do I access controls from the parent page from within an ASP.NET User Control?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM