LinkButton on main page does not launch Child second page in ASP.NET

I am creating a project in ASP.NET (Framework 4.0). I used Asp LinkButton on the main page and it has two pages linked to it (Home.aspx and service.aspx).

Question: This LinkButton1 works with Home.aspx and does not work on service.aspx .

User.master code as follows

<ul class="nav navbar-nav navbar-right"> <li> <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click" AutoPostBack="true">Signout <i class="glyphicon glyphicon-off"></i> </asp:LinkButton> </li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <span> <asp:Label ID="lblName" runat="server" Text=""></asp:Label> </span> <i class="icon-user fa"></i> <i class=" icon-down-open-big fa"></i> </a> <ul class="dropdown-menu user-menu"> <li class="active"> <a href="frmUserHome.aspx"> <i class="icon-home"></i> My Account </a> </li> <li > <a href="frmUserHome.aspx"> <i class="icon-home"></i> Personal Home </a> </li> <li> <a href="#"> <i class="icon-hourglass"></i> Pending approval </a> </li> </ul> </li> </ul> 

User.master.cs code for LinkButton1 Click

 protected void LinkButton1_Click(object sender, EventArgs e) { if (Request.Cookies["ASP.NET_SessionId"] != null) { Response.Cookies["ASP.NET_SessionId"].Value = string.Empty; Response.Cookies["ASP.NET_SessionId"].Expires = DateTime.Now.AddMonths(-20); } FormsAuthentication.SignOut(); Session.Abandon(); Response.Redirect("~/Default.aspx"); } 

While checking an item (using the Chrome browser) on the Home.aspx page, I found the code below

 <li> <a id="ctl00_LinkButton1" autopostback="true" href="javascript:__doPostBack('ctl00$LinkButton1','')">Signout <i class="glyphicon glyphicon-off"></i> </a> </li> 

and while on service.aspx (Chrome browser validation element)

 <li> <a id="ctl00_LinkButton1" autopostback="true" href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$LinkButton1", "", true, "", "", false, true))'>Signout <i class="glyphicon glyphicon-off"></i> </a> </li> 

Why is there a difference between Home.aspx and service.aspx (when checking an item through the Chrome browser)?

+5
source share
1 answer

Thanks for the original Answer by the author and thanks for @Nimesh for providing the link.

Set the PostBackUrl property to manage the LinkButton server, which means it is cross-publishing, and then the asp.net structure instead of the usual __DoPostBack () adds "WebForm_DoPostBackWithOptions".

I'hv made some changes according to my code requirement.

Code for LinkButton1 page (User.master)

  <li> <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click" PostBackUrl="~/Default.aspx">Signout <i class="glyphicon glyphicon-off"></i> </asp:LinkButton> </li> 

If in your case you did not set "PostBackUrl", then the ASP.NET structure also does not add this by default for Button Control, so this means that there should be another control, the value of the OnClick attribute, probably using the next rank side code.

Code for User.master.cs

 protected void LinkButton1_Click(object sender, EventArgs e) { if (Request.Cookies["ASP.NET_SessionId"] != null) { Response.Cookies["ASP.NET_SessionId"].Value = string.Empty; Response.Cookies["ASP.NET_SessionId"].Expires = DateTime.Now.AddMonths(-20); } FormsAuthentication.SignOut(); Session.Abandon(); PostBackOptions myPostBackOptions = new PostBackOptions(this); myPostBackOptions.ActionUrl = "~/Default.aspx"; myPostBackOptions.AutoPostBack = false; myPostBackOptions.RequiresJavaScriptProtocol = true; myPostBackOptions.PerformValidation = true; // Add the client-side script to the HyperLink1 control. LinkButton1.OnClientClick = Page.ClientScript.GetPostBackEventReference(myPostBackOptions); Response.Redirect("~/Default.aspx"); } 
0
source

Source: https://habr.com/ru/post/1242389/


All Articles