[英]how to open a new tab with session by clicking link button in asp.net c#?
I have a link button inside repeater and i just want to open it in a new tab with session. 我在中继器中有一个链接按钮,我只想在带有会话的新标签中打开它。 I have tried many things but it doesn't work well.
我已经尝试了很多东西,但是效果不佳。
<asp:Repeater runat="server" ID="RP_UniversityInfo">
<ItemTemplate>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="boxes">
<div class="boxes_img ImageWrapper">
<asp:LinkButton runat="server" ID="Link_Uni_Image"
CommandName="Link_Uni_Image"
CommandArgument='<%#Eval("id") %>'
OnClick="Link_Uni_Image_Click">
<img class="img-responsive"
src='<%# "upload/"+ Eval("image") %>' alt='<%#Eval("name") %>'>
<div class="PStyleNe"></div>
</asp:LinkButton>
<div class="box_type"><%#Eval("con_name") %></div>
</div>
<h2 class="title">
<asp:LinkButton runat="server" ID="Link_Uni"
CommandName="Link_Uni"
CommandArgument='<%#Eval("id") %>'
OnClick="Link_Uni_Click">
<%#Eval("name") %>
</asp:LinkButton>
</h2>
</div><!-- end boxes -->
</div>
</ItemTemplate>
</asp:Repeater>
LinkButton LnkBtn = (LinkButton)sender;
RepeaterItem item = LnkBtn.NamingContainer as RepeaterItem;
University_Id = Convert.ToInt32(LnkBtn.CommandArgument);
Session["university"] = University_Id;
Response.Redirect("University_Details.aspx");
I tried JavaScript also but same result. 我也尝试过JavaScript,但结果相同。 It opens a new tab but refreshes whole page and also opens new tab by clicking on Dropdownlist also.
它会打开一个新选项卡,但会刷新整个页面,也可以通过单击Dropdownlist来打开新选项卡。 Help me out!
帮帮我!
I suggest you to use <asp:HyperLink>
that will open link in new tab. 我建议您使用
<asp:HyperLink>
,它将在新选项卡中打开链接。
<asp:HyperLink NavigateUrl="http://websiteurl.com" Target="_blank" />
Because the
LinkButton
control is used to create a hyperlink-style button on the Web page.因为
LinkButton
控件用于在网页上创建超链接样式的按钮。 TheLinkButton
control has the same appearance as aHyperLink
control, but has the same functionality as a Button control.LinkButton
控件的外观与HyperLink
控件相同,但功能与Button控件相同。 If you want to link to another Web page when the control is clicked, consider using theHyperLink
control.如果要在单击控件时链接到另一个网页,请考虑使用
HyperLink
控件。
Edit : If you can not change to HyperLink then follow below approach. 编辑:如果您不能更改为HyperLink,则请遵循以下方法。
Add OnClientClick event. 添加OnClientClick事件。
OnClientClick="aspnetForm.target ='_blank';"
So on click it will call JavaScript
function and it will open respective link in new tab. 因此,单击它会调用
JavaScript
函数,并会在新标签页中打开相应的链接。
<asp:LinkButton id="lnkLink" OnClientClick="aspnetForm.target ='_blank';" runat="Server" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.