如何根据锚标记的id更改页面内容? [英] how to change content of page based on id of an anchor tag?

查看:117
本文介绍了如何根据锚标记的id更改页面内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面说page1.aspx我有很多锚标签,如sony,samsung,dell,micromax等..当我点击任何这些标签(即sony,samsung,dell,micromax).page1.aspx将重定向到page2.aspx ...其中数据根据我使用的锚标签而变化。例如...如果我使用sony ... page2.aspx中的内容将仅显示sony的详细信息...同样......现在我的问题是如何实现dis使用session。

i have a page say page1.aspx where i have many anchor tags like sony,samsung,dell,micromax etc.. when i click on any of these tags(ie sony,samsung,dell,micromax) .page1.aspx will redirect to page2.aspx...where data change based on the anchor tag i used.for example... if i use sony..the content in page2.aspx will show details of sony only... likewise... now my question is how can i achieve dis using session.

推荐答案

在服务器端处理所有点击。



您还需要拥有所有锚点runat =server和NavigateUrl / href =#,以便它们在运行服务器端代码后重定向。 (或者至少我认为他们会在去服务器端之前重定向,你可以在做之前检查一下......)



On your server side handler for all clicks.

You also need to have all anchors runat="server" and NavigateUrl / href = "#" so that they redirect after they run through server side code. (or at least I think they will redirect before going server-side, you may check that before doing it...)

protected void anchor_click (object sender, EventArgs e) {
    Session("manufacturer") = "Sony"; // here you need to get the value of the clicked anchor

    Response.Redirect("Page2.aspx", true);
}







更好的解决方案是在加载过程中设置queryString参数然后你不要必须处理点击,他们将正确地重定向,在第2页你需要检查queryString而不是会话变量




Better solution is to set queryString parameters during loading and then you don't have to handle clicks, they will redirect properly and on page2 you need to check queryString instead of session variable


是的,它可以通过使用session来实现,

在页面加载检查会话返回的基础上,只显示该锚标记,隐藏其他人

你需要给你的锚标签。
Yes, it can be achieved by using session,
on page load check what session returns, on the basis of that show only that anchor tag, hide others
you need to give Id to your anchor tag.


这篇关于如何根据锚标记的id更改页面内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆