我正在解析 RSS 提要的 xml 并显示它。我想刷新一个显示最近新闻的 div。我正在使用更新面板和 asp 计时器来执行此操作(请参阅下面的代码),但每次刷新整个页面都会刷新。
谁能让我知道我哪里出错了
protected void Page_Load(object sender, EventArgs e)
{
string loggedinuser = "experiment4";
Read_Rss(loggedinuser);
var rssFeed = from el in doc.Elements("rss").Elements("channel").Elements("item")
orderby datetime(el.Element("pubDate").Value) descending
select new
{
Title = el.Element("title").Value,
Link = el.Element("link").Value,
Description = replace_other(el.Element("description").Value),
// Image = regex(el.Element("description").Value),
Image =
el.Element(media + "thumbnail") != null ?
el.Element(media + "thumbnail").Attribute("url").Value :
el.Element(media + "content") != null ?
el.Element(media + "content").Attribute("url").Value :
regex(el.Element("description").Value) != null ?
regex(el.Element("description").Value) : null,
PubDate = datetime(el.Element("pubDate").Value),
};
lvFeed.DataSource = rssFeed;
lvFeed.DataBind();
Data_Load(sender, e);
}
protected void Data_Load()
{
// try
//{
string loggedinuser = "experiment4";
Read_Rss(loggedinuser);
var rssFeed = from el in doc.Elements("rss").Elements("channel").Elements("item")
orderby datetime(el.Element("pubDate").Value) descending
select new
{
Title = el.Element("title").Value,
};
newFeed.DataSource = rssFeed;
newFeed.DataBind();
}
<div id="leftcolumn">
<asp:ListView runat="server" ID="lvFeed">
<LayoutTemplate>
<ul>
<li runat="server" id="itemPlaceHolder"><a></li>
</ul>
</LayoutTemplate>
<ItemTemplate>
<div class="box">
<strong>
<%#Eval("Title") %>
: </strong>
<br />
<br />
<img src="<%#Eval("Image")%>" alt="" id="photo" class="photo" onload="imageload(this,0,100)"
onerror="onImgError(this,0)"></img>
<%#Eval("Description")%><a href="<%#Eval("Link") %>">readmore</a><br />
<br />
<br />
</div>
</ItemTemplate>
</asp:ListView>
</div>
<div id='rightcolumn'>
<div id='side'>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer2" OnTick="Data_Load" runat="server" Interval="300">
</asp:Timer>
<asp:ListView runat="server" ID="newFeed">
<LayoutTemplate>
<ul>
<li runat="server" id="itemPlaceHolder"><a></li>
</ul>
</LayoutTemplate>
<ItemTemplate>
<div class="small">
<%#Eval("Title") %>
:<a href="<%#Eval("Link") %>">readmore</a><br />
</div>
<br />
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
</div>