use ajax into repeater to update data - asp.net

I've a repeater ASP.NET control that contain an image slider that display 3 images every 10 sec by random from DB.I used a UpdatePanel ASP.NET control to reload this repeater .every things is OK, but I've a problem, when passed 10 seconds page is refresh! and i don't want to refresh page.How to fix this problem?
this is ASP.NET code:
<div id="middleSliderArea">
<div class="pikachoose">
<ul id="pikame">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<li>
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<asp:Timer runat="server" ID="Timer1" Interval="10000" OnTick="Timer1_Tick"></asp:Timer>
<a href='<%#"MoreInfo.aspx?id="+Eval("ID") %>'>
<img runat="server" src='<%#Eval("Image") %>' /></a><span><%#Eval("Brief") %></span>
</ContentTemplate>
</asp:UpdatePanel>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
</div>
and you can see this effect here after 10 seconds.

You need to get all images ID's from DB to client Side (you use JSON object) at the beginning , after page load.
Then use "setInterval javascript method" and call another Javascript Method (for examle changeImage() ).
In changeImage() method you select img elements in the repeater than you can change the values and images. I know the explanation is not enought for you right now , if you need more I can help you ..

Related

asp.net formview generates table at fixed width 259px

Dynamically generated table in FromView is causing problem in my JQuery Mobile page. I have narrowed it down to the table that is generated is fixed at a width of 259px with an ID of table#ctl00_ContentPlaceHolder1_FormView1
I'm not sure how to change this to dynamic in asp.net FromView:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="FDID" DataSourceID="AccessDataSource1" DefaultMode="Insert">
<EditItemTemplate>
<ul data-role="listview" id="ul-edit-picks" data-divider-theme="a" data-inset="true" data-scroll="true">
<li data-role="list-divider">
<h2 id="itemTitle">
<asp:Label ID="Label1" runat="server" Text='<%# Eval("FDID")%>' Font-Bold="True" Font-Size="Medium"></asp:Label>
: Selections</h2>
</li>
...
I know this is a very old post - you can just not generate the formview inside a table
asp:FormView ID="MyFormView" **RenderOuterTable="false"
ok not sure why the <FormView> defaulted to 259px but the fix was to add Width="100%" to the control, I have never had this issue in the past, but I guess I just liked the default look.

ASP.NET ListView Paging : Invalid viewstate

I have a ListView control as follows (for posting here I've removed the values from my ItemTemplate):
<asp:ListView ID="ListView1" runat="server" DataSourceID="MyDataSource">
<LayoutTemplate>
<div id="requests" runat="server">
<asp:Panel runat="server" id="itemPlaceholder"></asp:Panel>
</div>
<asp:DataPager runat="server" ID="DataPager" PageSize="3">
<Fields>
<asp:NumericPagerField ButtonCount="10" PreviousPageText="<--" NextPageText="-->" />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<div ID="itemPlaceholder" class="request" runat="server">
<asp:LinkButton ID="button" runat="server" Text='...' CommandName="..."
CommandArgument='...' OnClick="..."
style="...">
</asp:LinkButton> -
</div>
</ItemTemplate>
</asp:ListView>
This ListView exists as a user control (.ascx), which I've embedded into an ASPX web page.
As I expect, when the web page loads, for a list of 9 items, I get 3 pages of 3 items.
When I click to go to the next page, the page loads the next set of items correctly... but only for a brief second. Then a strange thing happens. The page embeds a copy of itself inside the page 6 times, each one of them underneath one of the fields on the form inside the page.
If I then attempt to go to the next or previous page, an ASP.NET server error appears:
The state information is invalid for this page and might be corrupted.
In the stack trace, it shows the following errors:
FormatException: The input is not a valid Base-64 string as it contains a non-base character, more than two padding characters, or a non-white space character among the padding characters.
ViewStateException: Invalid viewstate.
I was able to replicate this on both my browsers, IE8 and Chrome.
you use listview event OnPagePropertiesChanging
like this
<asp:ListView ID="lvCustomers" runat="server" GroupPlaceholderID="groupPlaceHolder1"
ItemPlaceholderID="itemPlaceHolder1" OnPagePropertiesChanging="OnPagePropertiesChanging">
in aspx.cs
protected void OnPagePropertiesChanging(object sender,PagePropertiesChangingEventArgs e)
{
(lvCustomers.FindControl("DataPager1") as DataPager).SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
this.BindListView();
}
BindListView() is method for binding list view
visit this link for example
i hope it's helpfull

ASP.NET Form Partial Submit

I have this code in form:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="Text1" runat="server"></asp:TextBox>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="Text2" runat="server"></asp:TextBox>
<asp:Button ID="Submit" runat="server" OnClick="Submit_Click"
Text="Click Me"/>
</ContentTemplate>
</asp:UpdatePanel>
When I click on Submit button, the all form is posted back on server (Text1 and Text2). I want to post back only textbox in UpdatePanel (Text2). Is it possible?
Thank you for responses.
EDIT (Solution):
I think, I have solution using Javascript:
function onSubmit() {
var text1 = this.document.getElementById('<%=Text1.ClientID%>');
text1.disabled = true;
return true;
}
....
<asp:Button ID="Submit" OnClientClick="onSubmit();" ..../>
It cause that Text1 will be disabled before PostBack. It seams that ASP.NET do not post back values from disabled textboxes. Hovewer, this works only without UpdatePanel. Of course, Text1 is empty after postback.
Well, the UpdatePanel controls what get's posted back. You cannot change that behavior. It should be posting the form data for the UpdatePanel only (I believe), plus the entire ViewState. It has to post the entire ViewState for the page lifecycle to work.

Passing Value Through Link Button in ASP.NET

Conditions :
I have two tables,
category(id_kat,name_kat)
book(id_book,id_kat,name_book)
id_kat has a child and parent relations.
I'm a little bit confused using ASP.NET, especially when passing value between pages.
Now, i'm showing the category's datas with
<asp:listview id="listview1" runat="server" datakeynames"id_kat" datasourceID="sdskat">
//FYI sdskat is datasource for category table
<itemtemplate>
<li>
<asp:linkbutton id="linking" runat="server" ><%# Eval("name_kat") %></asp:linkbutton>
</li>
</itemtemplate>
</asp:listview>
The problem is, i wanted to pass "id_kat" value when i click the hyperlink. (but redirected to self page).
I want it as a query string (or another way if able).
Thanks a lot.
If you're linking to the same page with different query string parameters, you only need to include ? and after.
<%# Eval("name_kat") %>
You could use <asp:hyperlink id="linking" runat="server" ><%# Eval("name_kat") %></asp:hyperlink> instead. You can then add your url in the navigateURL attribute and append your id_kat on there.
Something like this should work:
<asp:hyperlink id="linking" runat="server" navigateURL="~/page.aspx?id_kat=<%# Eval('id_kat') %>" ><%# Eval("name_kat") %></asp:hyperlink>
the <asp:hyperlink> tag is essentially the tag but using a server side control.
If you have to use a linkbutton then in your code behind you can append the id_kat to the querystring and then response.redirect(url) to the new page.
Why not use a regular anchor?
<a href='foo.aspx?id=<%# Eval("id_kat") %>'><%# Eval("name_kat") %></a>

How to make UpdatePanel inside ListView work?

I have a page with a listview that shows something like posts. On each post there should be a "rate box" which works similar to the "Like" button in facebook. The rate box is a User Control, that has an update panel inside it.
If I put the control with some random values in the page it works great - but when I put it inside the ListView, where it should be located, it won't work. The method is being called, but nothing happens.
I simplified the code a bit to make it easier to understand:
The "rate box" control:
protected void OnRateClick(object sender, ImageClickEventArgs e)
{
Rate++;
RateAmountLiteral.Text = Rate.ToString();
RateButton.Visible = false;
FeedbackLiteral.Visible = true;
rateButtonPanel.Update();
}
ascx:
<div class="rate_div">
<asp:UpdatePanel ID="rateButtonPanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<fieldset>
Rate:
<asp:Literal ID="RateAmountLiteral" runat="server"></asp:Literal>
<asp:ImageButton ID="RateButton" runat="server" ImageUrl="icn_rate.png"
OnClick="OnRateClick" />
<asp:Literal ID="FeedbackLiteral" runat="server" Visible="false">Thanks for rating!</asp:Literal>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
</div>
aspx (using the control):
<asp:ListView ID="PostsView" runat="server" ItemPlaceholderID="itemPlaceHolder2"
<LayoutTemplate>
<div class="posts_div">
<asp:PlaceHolder ID="itemPlaceHolder2" runat="server" />
</div>
</LayoutTemplate>
<ItemTemplate>
<div class="post_div">
<div class="post_body">
<%# CurrentPost.Body %>
</div>
<UC:RatingBox id="RatingBox" runat="server"
PostID="<%# CurrentPost.ID %>"
Rate="<%# CurrentPost.Rate %>"/>
By: <a href="<%# CurrentPost.Author.LinkToProfile %>">
<%# CurrentPost.Author.DisplayName %>
</a> |
<%# CurrentPost.LiteralTime %>
</div>
</ItemTemplate>
</asp:ListView>
While debugging I noticed the controls in the method "OnRateClick" are empty and don't contain the right values. Please advice.
Also if you have any comments about the way I did things, don't hold yourself.
Thanks
There are a lot things that you may not have set up, I cannot tell from just the code snippet you have given. But make sure you do the following: -
1) Place a ScriptManager "" on the page.
If you are using master page in your application and your web page uses the master page, place script manager in master page. Or alternatively,you can also place script manager on specific web pages anyway.
2) Add a Triggers for the button RateButton in your Update panel.

Resources