[英]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.