1

我是开发 .NET 的新人

我在 javascript 中动态创建一个标签。按下页面上创建的按钮后。

<label name="lblPerson1" id="lblPerson1" runat="server">Person:</label>

之后我想在服务器端捕获这个标签。

来人帮帮我!

编辑:

我想要的是能够在您单击按钮时创建一组标签和输入。(在客户端)然后当您单击另一个按钮以更改标签的文本时(在服务器端)它是可能的吗?

4

2 回答 2

1

The label won't be posted to the server as part of the post request because it is not an input control.

What you can do (for example) :

  • have a asp.net hidden input control where, using some javascript, you will store the label's html markup upon click on the submit button, before submitting the form
  • or, upon click on the submit button, perform a post ajax request, where you will put your label's html markup

And BTW, I don't see how you will be able to use the runat="server" unless you parse the HTML markup server side to generate server controls (which does not seem a simple idea to me)

Hope this will help

于 2013-03-06T15:39:55.690 回答
-1

因为此控件不是在服务器端创建的,所以您需要使用 FindControl 方法,如下所示:

使用这样的控件:

    <label name="lblPerson1" id="lblPerson2" runat="server">Person:</label>

    Dim myLabel As HtmlGenericControl
    myLabel = Me.lblPerson2

    Dim test As String = myLabel.InnerText

让我知道这是否有效。

于 2013-03-06T15:34:49.637 回答