Display nested replies for a comments in a blog - c#

I'm developing a blog that has a section for getting some comments and replies from the users. The first part is of my code for getting the comments and replies is the following one:
C# code:
var a = commentBLL.GetAll(BlogID);
rp_MainComments.DataSource = a;
rp_MainComments.DataBind();
protected void rp_MainComments_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
LinkButton btn = e.Item.FindControl("btn_Comment_Reply") as LinkButton;
ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(btn);
HiddenField lt = (HiddenField)e.Item.FindControl("hf_Main_CommentID");
Repeater rpcommentreply = (Repeater)e.Item.FindControl("rp_Comment_Reply");
Panel panel_Comment_Reply = e.Item.FindControl("panel_Comment_Reply") as Panel;
if (!string.IsNullOrEmpty(lt.Value))
{
var b = commentBLL.GetByCommentID(Convert.ToInt32(lt.Value));
rpcommentreply.DataSource = b;
rpcommentreply.DataBind();
panel_Comment_Reply.Visible = false;
}
}
}
ASPX code:
<asp:Repeater ID="rp_MainComments" OnItemDataBound="rp_MainComments_ItemDataBound" OnItemCommand="rp_MainComments_ItemCommand" runat="server">
<ItemTemplate>
<asp:HiddenField ID="hf_Main_CommentID" runat="server" Value='<%# Eval("Comment_Id") %>' />
<ul class="comments">
<li>
<div class="comment">
<div class="img-thumbnail d-none d-sm-block">
<%--<asp:Image ID="Image_7" CssClass="avatar" runat="server" ImageUrl="http://placehold.it/40x40" />--%>
<i class="fa fa-user fa-fw fa-5x"></i>
</div>
<div class="comment-block">
<div class="comment-arrow"></div>
<span class="comment-by">
<strong><%# Eval("Name") %></strong>
<span class="float-right">
<span>
<asp:LinkButton ID="btn_Comment_Reply" Text="Reply" ClientIDMode="AutoID" runat="server" OnClick="btn_Comment_Reply_Click" CommandName="Edit" CommandArgument='<%# Eval("Comment_Id") %>' /></span>
</span>
</span>
<p><%# Eval("Message") %></p>
<span class="date float-right">
<%# Eval("Comment_Date") %></span>
</div>
</div>
</li>
<li>
<asp:HiddenField ID="hf_PanelValue" Value='<%# Container.ItemIndex %>' runat="server" />
<asp:Repeater ID="rp_Comment_Reply" OnItemCommand="rp_Comment_Reply_ItemCommand" runat="server">
<ItemTemplate>
<ul class="comments reply" id="commentreply">
<li>
<div class="comment">
<div class="img-thumbnail d-none d-sm-block">
<%--<asp:Image ID="Image_8" CssClass="avatar" runat="server" ImageUrl="http://placehold.it/40x40" />--%>
<i class="fa fa-user fa-5x fa-fw"></i>
</div>
<div class="comment-block">
<div class="comment-arrow"></div>
<span class="comment-by">
<strong><%# Eval("Name") %></strong>
<span class="float-right">
<span>
<asp:LinkButton ID="btn_Reply" Text="Reply" ClientIDMode="AutoID" runat="server" OnClick="btn_Reply_Click" CommandName="Edit" CommandArgument='<%# Eval("Parent_Id") %>' /></span></span>
</span>
<p><%# Eval("Message") %></p>
<span class="date float-right"><%# Eval("Comment_Date") %></span>
</div>
</div>
</li>
</ul>
</ItemTemplate>
</asp:Repeater>
</li>
</ul>
</ItemTemplate>
</asp:Repeater>
This is the output:
Now, I would like to to show the nested replies to which user reply in a post it's shown only upto second level but I need a third as well as fourth level.
How is it possible?

Related

How to do file upload in a datalist?

protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
FileUpload file = (FileUpload)DataList1.FindControl("FileUpload1");
file.SaveAs(Request.MapPath("//") + "resume//");
}
This is the datalist:
<asp:DataList ID="DataList1" runat="server" OnSelectedIndexChanged="DataList1_SelectedIndexChanged" OnItemCommand="DataList1_ItemCommand">
<ItemTemplate>
<div class="jumbotron">
<div class="card-primary">
<asp:LinkButton ID="job_pos" runat="server" Font-Size="XX-Large"><%#Eval ("JobPosition") %></asp:LinkButton>
<h4 style="font-weight: bolder"><%#Eval ("CompanyName") %> <span class="icon"><i class="fa fa-building"></i></span></h4>
<h5 style="font-weight: bold; color: #808080"><%#Eval ("Region") %> <span class="icon"><i class="fa fa-map-marker"></i></span></h5>
<h5 style="font-weight: bold; color: #808080"><%#Eval ("ExactAddress") %></h5>
<div>
<h5><%#Eval ("JobDesc") %></h5>
<div>
<asp:Label ID="Label2" runat="server" Text="Interested? Apply Now!" Font-Bold="True" ForeColor="Red"></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" CssClass="primary"/>
<asp:Button ID="Button1" runat="server" Text="Upload Resume" OnClick="Button1_Click" CssClass="btn-primary" CommandName="UPDATE"/>
</div>
</div>
</div>
</div>
</ItemTemplate>
</asp:DataList>

Alertify.JS and ASP.NET: Call Javascript from Code-behind

I have a question.
I am now using the current version of Alertify.js found here. I wanted to integrate it with my ASP.NET application. When I click the Save button from my Modal Dialog, it proceeds to the code-behind without problems. I've tried "alert("Test");" inside the ScriptManager.RegisterClientScriptBlock and it does render.
Now when I try to use my custom function located in one of the files I've added, it seems the script does not respond, i.e. Alertify does not show.
Here is the JavaScript code from my custom JS file, my C# Code behind for that Save button, and the ASP.NET Page.
JS
function callFeedbackMessage(inputType, inputText) {
var inputFeedback = inputType;
e.preventDefault();
if (inputType == 'Error') {
alertify.error(inputText);
return false;
}
else if (inputType == 'Success') {
alertify.success(inputText);
return false;
}
else {
alertify.log(inputText, "", 10000);
return false;
}
}
C# Code Behind of lnkSave_Click
protected void lnkSave_Click(object sender, EventArgs e)
{
Category newCategory = new ProgrammersToolkitLibrary.BOM.Category();
bool isSuccess = true;
newCategory.CategoryName = txtCategoryName.Text;
newCategory.Description = txtDescription.Text;
isSuccess = CategoryController.CreateNewCategory(newCategory);
if (isSuccess == true)
{
grdCategoriesList.DataBind();
upCategoriesList.Update();
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "alert", "callFeedbackMessage('Success', 'Okay');", true);
}
else
{
}
}
ASP.NET Page
<%# Page Title="" Language="C#" MasterPageFile="~/Layout/Layout.Master" AutoEventWireup="true" CodeBehind="Category_List.aspx.cs" Inherits="ProgrammersToolkit.Views.Maintenance.Categories.Category_List" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div style ="text-align:left;">
<h3>Article Categories</h3>
<div class="btn-group">
<button class="btn btn-default" data-toggle="modal" data-target="#AddCategoryModal"><span class="glyphicon glyphicon-plus"></span> Add Category</button>
<asp:LinkButton ID="LinkButton2" runat="server" CssClass="btn btn-default"><img src="../../../Layout/img/Icon_Excel.gif" /> Export to Excel</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" CssClass="btn btn-default"><img src="../../../Layout/img/Icon_Excel.gif" /> Import from Excel</asp:LinkButton>
</div>
</div>
<br /><br />
<div class="panel panel-default">
<div class="panel-heading">
<div class="row">
<div class ="col-lg-6">
<div class="input-group">
<asp:TextBox ID="txtSearch" runat="server" CssClass="form-control"></asp:TextBox>
<span class="input-group-btn">
<asp:LinkButton ID="lnkSearch" runat="server" CssClass="btn btn-default">Search</asp:LinkButton>
<asp:LinkButton ID="lnkReset" runat="server" CssClass="btn btn-default">Reset</asp:LinkButton>
</span>
</div>
</div>
<div class ="col-lg-6"></div>
</div>
</div>
<div class="panel-body">
<asp:UpdatePanel ID="upCategoriesList" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="grdCategoriesList" runat="server" CssClass = "table table-hover table-responsive" Width="100%"
DataSourceID="odsCategoriesList" AllowPaging="true" PageSize="10" GridLines="None" BorderStyle="NotSet" BorderWidth="0px"
AutoGenerateColumns="false">
<PagerSettings FirstPageText="<< First" LastPageText="Last >>" NextPageText="Next >"
Position="Bottom" PreviousPageText="< Previous" />
<Columns>
<asp:TemplateField HeaderStyle-CssClass="input-group-addon" ItemStyle-CssClass="input-group-addon">
<ItemTemplate>
<asp:CheckBox ID="chkSelectItem" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="chkSelectAll" runat="server" />
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Category Name" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:LinkButton ID="lnkCategoryName" runat="server" OnCommand="lnkCategoryName_Command"
CommandArgument='<%# Eval("CategoryId") %>' CommandName='<%# Eval("CategoryName") %>'
Text='<%# Eval("CategoryName") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Description" HeaderText="Description" ItemStyle-HorizontalAlign="Left" />
</Columns>
<PagerStyle HorizontalAlign="Right" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:ObjectDataSource ID="odsCategoriesList" runat="server" EnablePaging="True" TypeName="ProgrammersToolkitLibrary.Controller.CategoryController"
SelectMethod="GetListOfCategories" SelectCountMethod="GetListOfCategoriesCount"></asp:ObjectDataSource>
</div>
<div class="modal fade" id="AddCategoryModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Add New Category</h4>
</div>
<div class="modal-body">
<table style="width:100%;text-align:left;">
<tr>
<td style = "width: 30%;"><label for="txtCategoryName">Category Name:</label></td>
<td>
<asp:TextBox ID="txtCategoryName" runat="server" CssClass="form-control"></asp:TextBox>
</td>
</tr>
<tr>
<td style = "width:30%; vertical-align:text-top;"><label for="txtDescription">Description:</label></td>
<td>
<asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" Rows="3" CssClass="form-control"></asp:TextBox>
</td>
</tr>
</table>
</div>
<div class="modal-footer">
<asp:LinkButton ID="lnkSave" runat="server" CssClass="btn btn-primary" OnClick="lnkSave_Click" ClientIDMode="Static">Save</asp:LinkButton>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</asp:Content>
Thank you.
Ju-chan

How do I bind a string array(list of files in my case) to a variable in the item template of a repeater?

How do I bind a string array(list of files in my case) to a variable in the item template?
Here is what I have so far but I am not sure what to do for the code behind itemdatabound.
I am trying to put each url in the <% Photo_URL %> variable.
Any help would be appreciated.
Thanks in advanced.
Page Code
<asp:Repeater id="unorderedList" runat="server" OnItemDataBound="unorderedList_ItemDataBound">
<HeaderTemplate>
<ul class="thumbs noscript">
</HeaderTemplate>
<ItemTemplate>
<li>
<a class="thumb" href='<%# Photo_URL %>'>
<img src='<%# Photo_URL %>'>
</a>
<div class="caption">
<div class="download">
<a href='<%# Photo_URL %>'>Download Original</a>
</div>
</div>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
Code Behind
private void Page_Init(object sender, EventArgs e)
{
string[] photos = Directory.GetFiles(ImagesLocation);
unorderedList.DataSource = photos;
unorderedList.DataBind();
}
protected void unorderedList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//what goes here
}
<div class="download">
<a href='<%# Container.DataItem %>'>Download Original</a>
</div>
No need for the ItemDataBound event, you just need to use the <%# Container.DataItem %> syntax, like this:
<ItemTemplate>
<li>
<a class="thumb" href='<%# Photo_URL %>'>
<img src='<%# Container.DataItem %>'>
</a>
<div class="caption">
<div class="download">
<a href='<%# Container.DataItem %>'>Download Original</a>
</div>
</div>
</li>
You can use the Container.DataItem syntax:
<asp:Repeater id="unorderedList" runat="server" OnItemDataBound="unorderedList_ItemDataBound">
<HeaderTemplate>
<ul class="thumbs noscript">
</HeaderTemplate>
<ItemTemplate>
<li>
<a class="thumb" href='<%#Container.DataItem%>'>
<img src='<%#Container.DataItem%>'>
</a>
<div class="caption">
<div class="download">
<a href='<%#Container.DataItem%>'>Download Original</a>
</div>
</div>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
You'll need to add a GridView in the ItemTemplate. Set it's DataSource to <%# Eval("string_list_name") %> where string_list_name is the variable name of your List of strings.

C# ASP.NET update panel inside a repeater error

I have a problem with an updatepanel when I put it inside a repeater control I get an error, and I need to refresh only a single post when the user click on a link button, here is my code...
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Repeater ID="Repeater1" runat="server"
OnItemCommand="MyButtonCommandEvent">
<ItemTemplate>
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<div class="post">
<asp:HiddenField ID="postID_hidden" runat="server"
Value='<%# DataBinder.Eval(Container.DataItem,"posts_ID") %>' />
<div class="Thumb">
<img src="thumbs/abdo_thumb.jpg"> </img></div>
<span class="user"><%#DataBinder.Eval(Container.DataItem, "poster_name")%>
</span>
<div class="post-body">
<p>
<%#DataBinder.Eval(Container.DataItem,"description")%>
</p>
</div>
<div class="post-options" style=" height:22px; ">
<span class="first"><%#DataBinder.Eval(Container.DataItem,"post_date")%></span>
<ul style="display:inline; list-style-type: none;">
<li>
<div class="tooltip">
Comments
<img class="tool-img" src="Images/comments.png"> : <%#DataBinder.Eval(Container.DataItem,"comment_num") %>
</img>
</div>
</li>
<li>
<div class="tooltip">
<asp:LinkButton ID="like_linkbtn" runat="server" CommandName="Like"><%#(DataBinder.Eval(Container.DataItem, "name_like").ToString() == "") ? "Like" : DataBinder.Eval(Container.DataItem, "name_like")%></asp:LinkButton>
<img class="tool-img" src="images/likes.png"> : <%#DataBinder.Eval(Container.DataItem,"like_counter") %>
</img></div>
</li>
<li>
<div class="tooltip">
<asp:LinkButton ID="hate_linkbtn" runat="server" CommandName="Hate"><%#(DataBinder.Eval(Container.DataItem, "name_hate").ToString() == "") ? "Hate" : DataBinder.Eval(Container.DataItem, "name_hate")%></asp:LinkButton>
<img class="tool-img" src="images/hate.png"> : <%#DataBinder.Eval(Container.DataItem,"hate_counter") %>
</img></div>
</li>
</ul>
</div>
<div class="finish">
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:Repeater>
The error is : Compiler Error Message: CS1061: 'System.Web.UI.Control' does not contain a definition for 'DataItem' and no extension method 'DataItem' accepting a first argument of type 'System.Web.UI.Control' could be found (are you missing a using directive or an assembly reference?).
This is making me really frustrated please help.
PS: It works if I removed the updatepanel and made it outside the repeater (The repeater inside the updatepanel instead of the updatepanel inside the repeater but that's not what I want)
Another solution is to cast Container as IDataItemContainer (((IDataItemContainer)Container)).
Instead of:
<%# DataBinder.Eval(Container.DataItem, "Column") %>
Use:
<%# DataBinder.Eval(((IDataItemContainer)Container).DataItem, "Column") %>
This solution is ideal if you are casting the DataItem as an object, eg:
<%# ((MyClass)Container.DataItem).ColumnName %>
This becomes:
<%# ((MyClass)((IDataItemContainer)Container).DataItem).ColumnName %>
Put Update panel out side of repeater. It will work.
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server"
OnItemCommand="MyButtonCommandEvent">
<ItemTemplate>
<div class="post">
<asp:HiddenField ID="postID_hidden" runat="server"
Value='<%# DataBinder.Eval(Container.DataItem,"posts_ID") %>' />
<div class="Thumb">
<img src="thumbs/abdo_thumb.jpg"> </img></div>
<span class="user"><%#DataBinder.Eval(Container.DataItem, "poster_name")%>
</span>
<div class="post-body">
<p>
<%#DataBinder.Eval(Container.DataItem,"description")%>
</p>
</div>
<div class="post-options" style=" height:22px; ">
<span class="first"><%#DataBinder.Eval(Container.DataItem,"post_date")%></span>
<ul style="display:inline; list-style-type: none;">
<li>
<div class="tooltip">
Comments
<img class="tool-img" src="Images/comments.png"> : <%#DataBinder.Eval(Container.DataItem,"comment_num") %>
</img>
</div>
</li>
<li>
<div class="tooltip">
<asp:LinkButton ID="like_linkbtn" runat="server" CommandName="Like"><%#(DataBinder.Eval(Container.DataItem, "name_like").ToString() == "") ? "Like" : DataBinder.Eval(Container.DataItem, "name_like")%></asp:LinkButton>
<img class="tool-img" src="images/likes.png"> : <%#DataBinder.Eval(Container.DataItem,"like_counter") %>
</img></div>
</li>
<li>
<div class="tooltip">
<asp:LinkButton ID="hate_linkbtn" runat="server" CommandName="Hate"><%#(DataBinder.Eval(Container.DataItem, "name_hate").ToString() == "") ? "Hate" : DataBinder.Eval(Container.DataItem, "name_hate")%></asp:LinkButton>
<img class="tool-img" src="images/hate.png"> : <%#DataBinder.Eval(Container.DataItem,"hate_counter") %>
</img></div>
</li>
</ul>
</div>
<div class="finish">
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>

fill controls of web user control from parent page

i have two web user control in one the grid view is showing the result and the other contains the simply textboxes and the dropdowns that are basically created to edit that gridview items
the aspx.cs page code is
GridView gView = PlaceHolder2.Controls[0].FindControl("grvBranches") as GridView;
int index = gView.SelectedIndex;
GridViewRow grd = gView.Rows[index];
Label lbl = (Label)grd.FindControl("lblID");
int rowid = 0;
int.TryParse(lbl.ToString(), out rowid);
In rowid i contains the id of that item which is selected
now i want to fill all the following items in webusercontrol
<div class="col2_form1">
<div class="form1_bar1">
<div class="form1_txt1_div">
<asp:Label ID="lblBranchName" runat="server" Text="Branch Name">
</asp:Label>
</div>
<div class="form1_txtfield_div">
<asp:TextBox runat="server" ID="txtBranchName" class="form1_TxtField" />
</div>
<div class="form1_txt2_div">
<asp:RequiredFieldValidator ID="RFVBranchName" ErrorMessage="*" Display="Dynamic"
ValidationGroup="Save" ControlToValidate="txtBranchName" runat="server" />
<%-- <asp:Label Text="Error" ID="lblBranchNameError" runat="server" />--%>
</div>
</div>
<div class="form1_bar2">
<div class="form1_txt1_div">
<asp:Label Text=" Organization Name" ID="lblOrganizationName" runat="server" />
</div>
<div class="form1_txtfield_div">
<asp:DropDownList ID="ddlOrganization" CssClass="form1_TxtField" runat="server">
</asp:DropDownList>
</div>
<div class="form1_txt2_div">
<%--<asp:Label Text="Error" ID="lblOrganizationNameError" runat="server" />--%>
</div>
</div>
<div class=" form1_bar1">
<div class="form1_txt1_div ">
<asp:Label Text="Address Line1" ID="lblAddresLine1" runat="server" />
</div>
<div class=" form1_txtfield_div">
<asp:TextBox runat="server" ID="txtAddresLine1" CssClass="form1_TxtField" />
</div>
<div class="form1_txt2_div ">
<asp:RequiredFieldValidator ErrorMessage="*" Display="Dynamic" ValidationGroup="Save"
ControlToValidate="txtAddresLine1" runat="server" />
</div>
</div>
<div class=" form1_bar2">
<div class="form1_txt1_div ">
<asp:Label Text="Address Line2" ID="lblAddresLine2" runat="server" />
</div>
<div class="form1_txtfield_div ">
<asp:TextBox runat="server" ID="txtAddresLine2" CssClass="form1_TxtField" />
</div>
<div class="form1_txt2_div ">
</div>
</div>
<div class="form1_bar1 ">
<div class="form1_txt1_div">
<asp:Label Text="Country" ID="lblCountry" runat="server" />
</div>
<div class="form1_txtfield_div " style="float: left;">
<asp:DropDownList ID="ddlCountry" AutoPostBack="true" CssClass="form1_TxtField" runat="server"
OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged">
</asp:DropDownList>
</div>
<div class=" form1_txt2_div">
</div>
</div>
<div class=" form1_bar2">
<div class="form1_txt1_div ">
<asp:Label Text="State" ID="lblState" runat="server" />
</div>
<div class="form1_txtfield_div ">
<asp:DropDownList ID="ddlState" AutoPostBack="true" CssClass="form1_TxtField" runat="server"
OnSelectedIndexChanged="ddlState_SelectedIndexChanged">
</asp:DropDownList>
</div>
<div class="form1_txt2_div ">
</div>
</div>
<div class="form1_bar1 ">
<div class="form1_txt1_div ">
<asp:Label Text="City" ID="lblCity" runat="server" />
</div>
<div class="form1_txtfield_div ">
<asp:DropDownList runat="server" CssClass="form1_TxtField" ID="ddlCity">
</asp:DropDownList>
</div>
<div class="form1_txt2_div ">
</div>
</div>
<div class="form1_bar2 ">
<div class="form1_txt1_div ">
</div>
<div class="form1_txtfield_div">
<asp:Button Text="Save" Width="100px" runat="server" ID="btnSave" ValidationGroup="Save"
OnClick="btnSave_Click" />
</div>
<div class="form1_txt2_div">
<asp:Label Text="" ID="lblMsg" Visible="false" runat="server" />
</div>
</div>
i have a property on the webusercontrol as
public string ABC_DEF
{
set { txtABC.Text = value; }
get { return txtABC.Text; }
}
and on the parent page i.e on the aspx page i call it as
if (ViewState["controlname"] != null)
{
PlaceHolder pl = MainPanel.FindControl(ViewState["controlname"].ToString()) as PlaceHolder;
pl.Controls.RemoveAt(0);
}
Control uc = (Control) Page.LoadControl("~/usercontrols/control_forms/branch_aspx_form.ascx");
ViewState["path"] = "~/usercontrols/control_forms/branch_aspx_form.ascx";
ViewState["controlname"] = "PlaceHolder1";
PlaceHolder1.Controls.Add(uc);
branch_view[] branch_to_edit = EntityService.ServiceInstance.GetBranchByBranchID(row_id);
foreach (branch_view item in branch_to_edit)
{
usercontrols.control_forms.branch_aspx_form branch_control =
new usercontrols.control_forms.branch_aspx_form();
branch_control.ABC_DEF = " hello"; // Call property here
}
thanks
Gurbax
In your user control .ascx file create properties for each of the fields you need to be pulled onto the user control,
Then you can simply access them from the .aspx page by specifying the UserControlId.Property syntax like so:
public string Name
{
get { return txtName.Text; }
set { txtName.Text = value; }
}
public string Surname
{
get { return txtSurname.Text; }
set { txtSurname.Text = value; }
}
On the .aspx page the properties can be accessed like this:
protected void PopulateUserControl_Click(object sender, EventArgs e)
{
userControlName.Name = "Bob";
userControlName.Surname = "The Builder";
}

Categories