Reputation: 1
I have struck in one doubt.
I am using one asp button. In this button click event I'm using if
and else
condition.
If
block shows one popup and else
block show another popup:
if (Session["id"] != null)
{
//one popup
}
else
{
//Second pop up Show
}
<asp:Button ID="btnAvailabilty" runat="server" class="btn btn-success" Text="Check Availability" OnClick="btnAvailabilty_Click" />
Upvotes: 0
Views: 1004
Reputation: 15860
You need to write that in client side if you need to write a JavaScript code there,
if (Session["id"] != null) {
ClientScript.RegisterStartupScript(this.GetType(), "something",
"alert('Your message');",
true);
} else {
ClientScript.RegisterStartupScript(this.GetType(), "something",
"alert('Your other message');",
true);
}
You can also try to run the message variable to be changed, while leaving maximum of the code in one statement,
var message = "Your message";
if (Session["id"] == null) {
message = "Your other message";
}
ClientScript.RegisterStartupScript(this.GetType(), "something",
$"alert({message});", // Requires C# 6
true);
If you can write native JavaScript, such as Razor, then that will go like,
<script>
@if (Session["id"] != null) {
alert('Your message');
} else {
alert('Your other message');
}
</script>
Depends on your need.
Upvotes: 1