I have a .aspx page in which I have a Asp:Button, clicking on which user browser(Opera) tab will be closed. After googling alot a found a solution to acheive this from code behind. (for Opera)
<asp:Button ID="BTN" runat="server" Text="close the window" onclick="BTN_Click"/>
I have put this code in Page.Load event.
BTN.Attributes.Add("onclick", "window.close();");
This is What it renders in HTML
<input type="submit" name="BTN" value="close the window" onclick="window.close();" id="BTN">
It is working fine as expected, user clicks the button and window is closed. Please note down browser is Opera.
Now look at the same code, the only difference is the button is inheriting Master Page and Content Panel Properties, so in this case it is rendered like this
<input type="submit" name="ctl00$MainContentPlaceHolder$BTN" value="close the window by clicking me" onclick="window.close();" id="ctl00_MainContentPlaceHolder_BTN" clientidmode="static">
Now user clicks on this but unexpectedly it just refreshes the browser window and doesn't close the window.
I have put these rendered codes here because i firmly beleive it is the ID which is the culprit. If it is so Can you please suggest me how to achieve this from code behind??