Repeater, Linkbutton and ModalPopupExtender without postback - c#

Here's my problem.
I have a repeater. Inside it has lots of textboxes. In the right most column, there is a linkbutton. This link button when clicked will show a modalpopupextender which will display the detail record of the selected row.
I have made it work just fine but its slow because when you click the linkbutton, it will refresh the whole page.
I don't want to reload the repeater because this is the part that is very slow.
I tried adding an updatePanel (repeater inside updatePanel) but ofcourse since the repeater is inside the updatePanel it will still reload the repeater.
So the question is, how do I do it so when the linkbutton is clicked, it wont reload the repeater...
Any ideas would be greatly appreciated.
By the way, I'm developing it with .net 2.0, c#

Try this one.
<asp1:UpdatePanel ID="updatepanel4" runat="server" >
<ContentTemplate>
<table id="AssignedRequest" class="tablecont" runat="server" style="width: 900px;" >
<tr>
<td>
<div style=" display:block; width:900px; height:350px;overflow:scroll; ">
<asp:Repeater runat="server" ID="RepeaterRequest">
<HeaderTemplate >
<table class="list_table" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<th>Name</th>
<th></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("NAME")%></td>
<td><a onclick="window.open(this.href,this.target,'directories=no,
menubar=no,resizable=no,scrollbars=1,
status=no,toolbar=no,addressbar=no,fullscreen=yes');
return false;" href="View.aspx?name=<%#Eval("NAME")%>">View</a></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</td>
</tr>
</table>
</ContentTemplate>
</asp1:UpdatePanel>

Register in the code behind, this code you add it after your bind, for example in your Page_Load, (You can also use ItemDataBound or ItemCreated delegate).
rpt.DataBind();
foreach (RepeaterItem ri in rpt.Items)
{
if (ri.ItemType == ListItemType.Item || ri.ItemType == ListItemType.AlternatingItem)
{
LinkButton lnkButton1 = (LinkButton)ri.FindControl("lnkButton1");
ScriptManager1.RegisterAsyncPostBackControl(lnkButton1);
}
}

Why not go for something like a master-child relationship. Do you require further interaction with the child data you are showing to the user? Please specify the nature if so.
Assuming that the child data that you are going to show is simple data meant to simply convey related data to user, you can go for a combination jQuery, and repeaters to accomplish your objective.
The first repeater you show your master data. Against each row in your repeater you show a show button here. You do not need a linkbutton here; just a simple anchor will do. You'd have to write js in it to toggle the correct child data.
All the child data should also be repeated. But not shown to the user at first. Only that particular child item should be shown - this is suitably triggered by the show anchor which is clicked on the master repeater. Rest is all js/css.
Below is a link to a sample project which demonstrates the concept.
http://www.coderun.com/ide/?w=2ObqOpjZz0qt7OrXYmmxwA

Related

ASP.NET Webform - How to place FormView and GridView next to each other

In my webform I have a gridview and a formview. The formview always appears under the gridview. How do I move the Formview to the right of the gridview?
GridView and FormView are render as tables, so one way is to use one warper table to place it side by side. Of course some will say that tables are not modern design and its better to use divs... ok this is just a fast solution.
<table>
<tr>
<td>
<asp:GridView></asp:GridView>
</td>
<td>
<asp:FormView></asp:FormView>
</td>
</tr>
</table>

Add control from content page in master page

I have a master page that looks something like this:
<table>
<tr>
<td>
<asp:Label ID="lbl1" runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lbl2" runat="server"></asp:Label>
</td>
</tr>
</table>
I use this design in all pages except one where i would like to add a button right after the first label - lbl1 (both of them to be on same row), and on the second row to see the second label.
My question is how could I achieve this from a content page (from code-behind preferable)?
Create <asp:Button runat="server" Visible="false" ... /> which by default have Visible = false. In the page which you want to see the button find the button and make it Visible = true.
When the Control is not visible it is not render, this is equal to not existing for other pages !

updating/ refreshing the controls which are in Rad ajax panel

I am facing problem in updating/ refreshing the controls which are in Rad ajax panel .
I have a Rad ajax panel in which i have placed a grid, and RadPanelBar side to side by placing them in table.
when the user selects any record in grid the details of that record will be shown in it's beside RadPanelBar. So
in this process of selecting records i am refreshing the Entire Rad ajax panel for getting the correct selected record details.
But additionally what i want is when the user sorts the records of grid i need to refresh the grid only , for this i placed
Radgrid again in other radajaxpanel which is creating the problems. My Radgrid is not getting updated with the click events of grid, when i click on link button of grid
it should highlight the clicked row. But when i placed grid in Ajax panel it is not getting highlighted untill unleass i refresh the Grid.
when i placed it in another nested rad ajax panel. Please help me how can i achieve refreshing the only the Radgrid while sorting?
My design:
<telerik:RadPageView ID="radPage1" runat="server">
<telerik:RadAjaxPanel ID="RadAjaxPanel3" runat="server" EnableAJAX="True" LoadingPanelID="RadAjaxLoadingPanel1"
ClientEvents-OnRequestStart="onRequestStart">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 50%">
<%-- <telerik:RadAjaxPanel ID="RadAjaxPanel4" runat="server" EnableAJAX="True" LoadingPanelID="RadAjaxLoadingPanel1"
ClientEvents-OnRequestStart="onRequestStart"> --%>
<telerik:RadGrid ID="radGrid" runat="server" AllowSorting="true" AllowFilteringByColumn="False"
OnNeedDataSource="grdUnResolvedFaxes_NeedDataSource" Skin="Metro" CellSpacing="0"
GridLines="None" Width="99%" PageSize="12" OnItemCommand="grdUnResolvedFaxes_ItemCommand"
EnableViewState="true">....
.....
.....
</telerik:RadGrid>
<%-- </telerik:RadAjaxPanel> --%>
</td>
<td style="width: 50%">
<telerik:RadPanelBar runat="server" ID="pnlBar" ExpandMode="MultipleExpandedItems"
Width="99%" Visible="false">
<Items>
.................
</Items>
</telerik:RadPanelBar>
</td>
</tr>
</table>
</telerik:RadAjaxPanel>
</telerik:RadPageView>
For the Linkbutton click of the grid i added below code to update the grid
if (e.CommandName.ToLower() == "select")
{
RadAjaxPanel4.ResponseScripts.Add(String.Format("$find('{0}').ajaxRequest();", RadAjaxPanel3.ClientID));
}
I am not sure what this linkbutton is, but from what I can gather, you want one action (an update on the grid) to do two different things (update the grid only, or also update the panelbar). This is quite a confusing scenario and I do not thing there is a way for the code to know when to only include one control.
Thus, you can consider using asp:UpdatePanel with UpdateMode=Conditional around the panelbar and call its Update() server method only when you need to rebind data in it. This can give you a conditional update there when needed. In this case, a RadAjaxPanel around the grid only should suffice.
Nesting AjaxPanels can cause issues as you have found, so you should avoid that.
If you know on the client that you need to update the panelbar you can show a RadAjaxLoadingPanel over its element with JavaScript as shown here: http://www.telerik.com/help/aspnet-ajax/ajax-show-hide-loadingpanel.html.

ASP.NET Listview->Click Row->Perform action

I need some help with the following.
I have a list view that I fill with code-behind:
Linq->Sql:
ListView1.DataSource = from x in database.ITEMS
select x;
ListView1.DataBind();
Content of ITEMS:
ID
Name
Quantity
I only show the name of the fields:
<tr>
<td>
<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("Name") %>' />
</td>
</tr>
Assuming I have 25 rows in the database, I fill the list view with 25 rows. Next is what I need help with. The user needs to click one of the 25 names (complete row) and redirects to a page where the content of that row is showed. So lets say someone clicks on "Cars", he'll be redirected and he will see: You have selected Cars, Cars has an ID of 19 and a Quantity of 6.
I have browsed the Internet already but I am having trouble finding solutions that I can understand. I am kind of a noob when it comes to list views and other data displaying methods.
My 2 questions:
How do I start a event when I click a row (and not a button or a link in that row)?
When I click a row and start a event, how can I check which one was clicked?
I hope someone can explain to me how this is done in a user friendly noob kind of way or redirect me to a tutorial discussing my issue's and also in a user friendly way. Thanks in advance.
Ok - I am not sure if this is the best way to go with this (I'll be interested what other think)... but this will work .
Update your listview to something like this:
<script type="text/javascript">
// simple redirect to your detail page, passing the selected ID
function redir(id) {
window.location.href = "mydetailpage.aspx?id=" + id;
}
</script>
<table>
<asp:ListView ID="ListView1" runat="server">
<ItemTemplate>
<tr onclick="redir('<%# Eval("ID") %>');">
<td>
<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("Name") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</table>
Then create another page to show your detail (e.g. mydetailpage.aspx) - this should requery your database and show the other fields, given the id passed in the querystring.
you can define onclick attribute to call javascript function on tr element like this :
onclick="yourfunction('<%# Eval("Name") %>');"
Then you can put anything in your javascript function like redirect to another page

Auto add a new row into Repeater Control when it has a new row inserted into SQL Server 2008 DB

This is so hard to understand, I'll try to describe my problem so clearly.
I have a Table in SQL DB:
COMMENT(idcom, content,user,idtopic);
I use a Repeater Control to display all the comment in Database:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table>
<tr>
<td>
</td>
<td>
<asp:Label ID="lblcontent" runat="server" Text='<%#Eval("content") %>'>
</asp:Label>
</td>
<td>
<asp:Label ID="lbluser" runat="server" Text='<%#Eval("user") %>'>
</asp:Label>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
My problem is: When client add a new comment (in another page)--> insert a new row into COMMENT table---> I have to load all the comment into Repeater again (both old comments and new comments).---> therefor, I use <UpdatePanel> and <Timer Control> Ajax Toolkit to update every 10sec. It's so amateur and not a good solution.
How can I just only load the new comment (new row) into the Repeater in every 10sec.
I always think Repeater is fixed and we cannot insert the single row.
Help! Can you give me some advice to insert single row into Repeater by load data from Database (not input directly)???
I'd say the best way to do this is with some Javascript/jQuery plugin + AJAX queries. ASP.NET Webforms does not usually works that way (it is prefered from the webform point of view to go through the entire page lifecycle for each update).
When you first populate your repeater, store the List and the biggest IdComm in variables, So you will use it in all subsequent selects you do in Database again.
Use the IdComm stored as a parameter and get all the new comments with IdComm bigger than the IDComm you have passed as parameter.
After that, add this new lines in the first list you have requested in the first request and populate the Repeater again in this updatePanel you are using.

Categories

Resources