I have a datalist and in that there is a button whoes ID="btnComment". when clicked on this button controls should be dynamically generated and added to panel named "PlComment".
------------------------------------------------------------------
ASPX code:
------------------------------------------------------------------
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DataList ID="dlAnswers" runat="server" RepeatColumns="1" RepeatDirection="Vertical">
<ItemTemplate>
<div class="comment-body comment-body-answered clearfix">
<div class="avatar">
<asp:Image ID="ProfileImg" runat="server" ImageUrl='<%#Eval("ProfileImg") %>' />
</div>
<div class="comment-text">
<div class="author clearfix">
<div class="comment-author"><a href='<%#Eval("FirstName")+" "+Eval("LastName") %>'></a></div>
<div class="comment-vote">
<ul class="question-vote">
<li><a href="#" class="question-vote-up" title="Like"></a></li>
<li><a href="#" class="question-vote-down" title="Dislike"></a></li>
</ul>
</div>
<span class="question-vote-result">+1</span>
<div class="comment-meta">
<div class="date"><i class="icon-time"></i><%#Eval("AnsDate") %>
</div>
<a class="button small green-button" href="#" style="float:right;padding:5px 15px; margin-left:300px">Accept Solution</a>
</div>
</div>
<div class="text">
<asp:Label ID="lblAnswer" runat="server" Text='<%#Eval("Description")%>'></asp:Label></p>
</div>
<div id="AnsCommentBox" class="question-answered question-answered-done">
<%----%>
<%----%>
<div id="divComment">
</div>
</div>
</div>
</div>
</ItemTemplate>
</asp:DataList>
<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>
---------------------------------------------------------------------------
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);
btnCancel.Click += btnCancel_Click;
}
protected void btnCancel_Click(object sender,EventArgs e)
{
PlComment.Visible = false;
btnComment.Visible = true;
}
What I have tried:
I have tried using FindControl() method but could not get it.
-----------------------------------------------------------------
Panel p = (Panel)dlAnswers.FindControl("PlComment");
p.Controls.Add(txtAnswerComment);
p.Controls.Add(btnSubmit);
p.Controls.Add(btnCancel);