javascript - LinkButton on Master Page doesn't fire on Second Child Page in ASP.NET -
i'm creating project in asp.net (framework 4.0). have used asp linkbutton in master page & has 2 page linked (home.aspx & service.aspx).
question follows : linkbutton1 works on home.aspx , doesn't work on service.aspx.
user.master code follow
<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> 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 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 inspect element (using chrome browser )on home.aspx page found below code
<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 inspect 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 difference between home.aspx & service.aspx (while inspect element through chrome browser) ?
thanks original answer writer & @nimesh providing link .
set postbackurl property linkbutton server control, means cross page posting , asp.net framework instead of normal __dopostback() adds "webform_dopostbackwithoptions".
i'hv made changes according code requirement .
code linkbutton1 (user.master) page
<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 case have not set "postbackurl", asp.net framework not add default button control, means there has control setting onclick attribute value using following sever side code .
code 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 client-side script hyperlink1 control. linkbutton1.onclientclick = page.clientscript.getpostbackeventreference(mypostbackoptions); response.redirect("~/default.aspx"); }
Comments
Post a Comment