Ok, I have a hyperlink on my page and that hyperlink is held within a user control. When the user clicks that link, it's used to remove an item on the page, so:
<a href='<%#string.Format("{0}?removeItem=true&ItemID={1}", CurrentPage, Container.DataItem.Id )%>'>Remove this item</a>
On click of the link, the code-behind of my user control checks for the removeItem bool and if set to true, removes that item:
removeSavedItem = Convert.ToBoolean(Request["removeItem"]);
if(removeItem)
RemoveItem();
And here's my RemoveItem() method:
protected void RemovItem()
{
int itemID = Util.ParamVal("savedItemID", 0);
if (itemID > 0)
service.RemoveItem(itemID);
}
But I need my page to refresh because it's removing it but my repeater is not showing the list with the item removed. What's the best way to approach this? Just do a rebind of the repeater or is there a cleaner way? Maybe that's just the standard way? Rebind after I remove it in this method?
I suggest trying to ajaxify the removal of the items, Unless you are changing a whole lot of things in the page.
As an answer to your question, you can do Response.Redirect(Request.Url.ToString());
Incase you want to do it from JavaScript for any reason then use window.location.reload();
Thanks
我更喜欢重定向回同一页面。
Response.Redirect(Request.Path);
为什么不在您的会话中保存已删除的项目,以免刷新不会引起他们的注意?
这是与pah和查询
Response.Redirect(Request.Url.PathAndQuery);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.