My idea is when the user isn't loged in he won't be able to add an item to the shopping cart, so what I did is like so:
<asp:Button ID="BTNAddToCart" runat="server" Text="Add to cart" class="btn btn-info btn-lg" style="display: inline; margin: auto; display: block; visibility: hidden;" OnClick="BTNAddToCart_Click" />
And then on code behind:
if (Session["User"] == null)
{
BTNAddToCart.Attributes["class"] = "btn btn-info btn-lg disabled";
BTNAddToCart.Attributes.Add("title", "Error");
BTNAddToCart.Attributes.Add("data-toggle", "popover");
BTNAddToCart.Attributes.Add("data-trigger", "hover");
BTNAddToCart.Attributes.Add("data-placement", "bottom");
BTNAddToCart.Attributes.Add("data-content", "You must be loged in to add items to the cart");
}
As You can see, by using Bootstrap I gave the button the look which he can't be clicked, but in reality He is still clickable.
So I thought that mabey if I will disable the button postback it will really be not clickable.
How can I disable the button postback?
I have tried:
<asp:Button ID="BTNAddToCart" runat="server" Text="Add to cart" class="btn btn-info btn-lg" style="display: inline; margin: auto; display: block; visibility: hidden;" OnClientClick="BTNJavaScriptClick()" OnClick="BTNAddToCart_Click" />
<script>
function BTNJavaScriptClick()
{
var ButtonAdd = document.getElementById("BTNAddToCart");
if (ButtonAdd.className == "btn btn-info btn-lg disabled")
return false;
}
</script>
I even tried BTNAddToCart.Enabled = false;
and it worked but it made my popover disapper.