单击动态添加按钮后如何显示原始控件 [英] How to display original control after clicking on dynamically added button

查看:54
本文介绍了单击动态添加按钮后如何显示原始控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码,其中点击评论按钮创建一个(多行文本框和两个按钮 - 提交和取消)。这些控件添加到面板PLComment中。单击取消按钮时,面板应隐藏,并且应显示注释按钮而不刷新页面。我也使用过AJAX。以下是代码。

------------------------------------- --------------------------------------------

ASPX:

-------------------------------------- --------------------------------------------

I have a code in which- on clicking on "Comment" button creates a ("multiline textbox",and two buttons- "Submit" & "Cancel"). These controls are added to panel "PLComment". On clicking on Cancel button the panel should hide and "Comment" button should be displayed without page refresh. I have used AJAX also. Below is the code.
---------------------------------------------------------------------------------
ASPX:
----------------------------------------------------------------------------------

<div id="AnsCommentBox" class="question-answered question-answered-done">
                                        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
                                        <asp:UpdatePanel ID="UpdatePanelComment" runat="server">
                                            <ContentTemplate>
                                                   <asp:Button ID="btnComment" runat="server" Text="Have a Comment?" CssClass="button btn btn-small" OnClick="PostComment" />
                                                <asp:Panel ID="PlComment" runat="server" ></asp:Panel>
                                            </ContentTemplate>
                                        </asp:UpdatePanel>
                                       <%-- <i class="icon-comments"></i>--%>
                                     
									</div>





---- -------------------------------------------------- ----------------------------

C#代码:

--- -------------------------------------------------- -----------------------------



----------------------------------------------------------------------------------
C# code:
----------------------------------------------------------------------------------

protected void PostComment(object sender,EventArgs e)
     {
         TextBox txtAnswerComment = new TextBox();
         Button btnSubmit = new Button();
         Button btnCancel = new Button();
         btnSubmit.Text = "Submit";
         btnCancel.Text = "Cancel";
         btnCancel.Style.Add("font-size", "12px;");
         btnCancel.Style.Add("Padding", "4px 10px;");
         btnCancel.Style.Add("font-size", "12px;");
         btnSubmit.Style.Add("Padding", "4px 10px;");

         btnSubmit.Attributes.Add("class", "button small blue-button");
         btnSubmit.Attributes.Add("runat", "server");
         btnSubmit.Style.Add("font-size", "12px");
         btnCancel.Attributes.Add("class", "button small red-button");
         btnCancel.Attributes.Add("runat", "server");

         txtAnswerComment.ID = "txtAnswerComment";
         txtAnswerComment.TextMode = TextBoxMode.MultiLine;
         txtAnswerComment.Style.Add("Width","700px;");
         txtAnswerComment.Style.Add("Height", "80px;");
         txtAnswerComment.Attributes.Add("runat", "server");
         txtAnswerComment.Font.Size = 9;
         txtAnswerComment.Style.Add("resize", "none;");
         PlComment.Controls.Add(txtAnswerComment);
         PlComment.Controls.Add(btnSubmit);
         PlComment.Controls.Add(btnCancel);
         btnComment.Visible = false;
        btnCancel.Click += btnCancel_Click;

     }

    protected void btnCancel_Click(object sender,EventArgs e)
        {
            
            PlComment.Visible = false;
            btnComment.Visible = true;
        }





我的尝试:



我尝试过使用AJAX但手动刷新页面后显示评论按钮。



What I have tried:

I have tried using AJAX but the "Comment" button shows after refreshing the page manually.

推荐答案

首先制作一个带有评论控件的虚拟html然后onclick按钮你需要附加html并通过jquery显示它。
First make a dummy html having comment controls then onclick button you need to append the html and show it via jquery.


这篇关于单击动态添加按钮后如何显示原始控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆