I have a div that acts as a popup in my master page called 'mydiv-clear'.
I have my main page content inside the div 'fade'.
I am able to successfully "popup" my div (change display from none to block) with Javascript OnClientClick if I use "return false;" in my OnClientClick to prevent postback (div goes back to display:none on postback).
I want to perform C# OnClick control for extra functionality within my popup. When I have return=false; in my OnClientClick I am not able to hit my C# OnClick code. When I remove return=false; my page is posted back and my display is back to display=none;. Solutions online suggested moving my button into an UpdatePanel control or to use UseSubmitBehaviour=false but neither of these have worked for me.
The below solution when I break through my code will fire my javascript (popup appears) cause a postback (popup disappears) and fire my C#. Can someone suggest a way to prevent postback and still fire C#? Thanks
.Net
<asp:Button ID="btnOptOut" OnClientClick="div_show();" UseSubmitBehavior="false" OnClick="btnOptOut_Click" CssClass="btn btn-default" runat="server" Text="Opt Out" />
C#
protected void btnOptOut_Click(object sender, EventArgs e)
{
try
{
_dal.createOptOutRecord(_myuser.id, _myuser.EmailAddress);
//More functionality to go here
}
catch(Exception ex)
{
}
}
Javascript
function div_show() {
document.getElementById('mydiv-clear').style.display = "block";
document.getElementById('fade').style.opacity = ".1";
}