使用JavaScript添加asp.net控制JavaScript、asp、net

2023-09-03 08:13:44 作者:六个字的诗意

我想补充一个 ASP:标签 ASP:文本框通过JavaScript控制到页面

I would like to add an ASP:label and ASP:textbox control to a page through Javascript.

<asp:Label ID="lblone" runat="server"></asp:Label>

如果我想写这个语法,或者想使用的innerHTML则希望可以顺便页上添加这个标签......

if i want to write this syntax or want to add this label on page using innerHTML then want can be the way....

我要添加按钮单击事件......和ID应该由1追加并在下一次1 + 1

I want to add it on button click event... and the ID should be appended by 1 and the next time 1+1

推荐答案

它需要是一个ASP .NET控件或可以仅仅是普通的HTML?

Does it need to be an ASP .NET control or could it just be normal HTML?

如果你想要一个ASP .NET控制这些,通过设计,呈现在服务器上,以便有要么需要使用以下方法之一添加控件:

If you want an ASP .NET control these, by design, are rendered on the server so there would either need to add the controls by using one of the following approaches:

1)同步回传(正常回发) 2)异步回发(JavaScript的回发不刷新页面直观,但仍然没有回发) 3)传统的Ajax

1) Synchronous PostBack (normal postback) 2) Async PostBack (javascript postback which doesn't refresh the page visually but still does a postback) 3) Traditional AJAX

您可能已经尝试了同步回传,因为你提的是,你想这样做在Javascript中。使叶片异步回发或传统的AJAX。

You've probably already tried the Sync PostBack since you're mentioning that you want to do this in Javascript. So that leaves Async PostBack or traditional AJAX.

在异步回发是最容易的,因为你只需要包装的一切在的UpdatePanel

The Async PostBack is the easiest because you just need to wrap everything in an UpdatePanel

<asp:UpdatePanel id="Updater" runat="server">
    <asp:PlaceHolder id="AddControlsToThis" runat="server" />
    <asp:Button id="Submit" runat="server" />
</asp:UpdatePanel>

对待这像一个正常的回发,并在codebehind添加任何控制要在占位符上按一下按钮。

Treat this like a normal postback and in the codebehind add whatever control you want to the placeholder on button click.

第三种方法(通过AJAX添加)是有点太多来形容这里,但基本上你会使用AJAX提出请求到Web服务,您将设立在服务器上,那么你就需要在渲染在服务器上的控制(每个控件都有RenderControl功能......你需要用它来获得生成的HTML),并使用生成的HTML发回的Web服务器的响应...对不起,如果这是一个小模糊。就像我说的传统的AJAX方法需要更多的描述比我能进入这里。

The third approach (adding via AJAX) is a little too much to describe here but basically you would use AJAX to make a request to a web service that you would set up on the server and then you would need to "render" the control on the server (each control has a RenderControl function...you would need to use this to get the resulting HTML) and use the resulting HTML to send back as a response of the web server...sorry if that's a little vague. Like I said the traditional AJAX approach requires more description than I can get into here.

祝你好运。