Click here to Skip to main content
15,884,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi CodeProject,
I am trying to use SweetAlert[^] in my project and using scriptmanager to show the sweetalert alert messages.

Here is my code.
XML
<script type="text/javascript">

        function Showalert() {
            swal("Good job!", "You clicked the button!", "success");
            return true;
        }

    </script>

my function where I am calling it
VB
Private Sub test()
     ScriptManager.RegisterStartupScript(Me, [GetType](), "displayalertmessage", "Showalert();", True)

 End Sub

and the code behind the button I am calling it from
VB
Protected Sub btnSendM_Click(sender As Object, e As EventArgs) Handles btnSendM.Click
        If txtName.Text = "Enter Name" Or txtName.Text = "" Or _
            txtEmail.Text = "Enter Email" Or txtEmail.Text = "" Or _
            txtPhone.Text = "Enter Phone Number" Or txtPhone.Text = "" Or _
            txtMessage.Text = "Enter Your Message." Or txtMessage.Text = "" Then
            'btnHidden_Click(sender, e)
            test()
        Else
            contactClass.sendMessage(txtName.Text, txtEmail.Text, txtPhone.Text, txtMessage.Text)
            'Button1_Click(sender, e)
        End If

    End Sub

The problem is if I change the swal in the Showalert() function to simple alert it works but swal dont works, I also included the SweetAlert css and js to the page which works if I put this code

XML
$(function () {
              $("#<%= btnHidden.ClientID%>").click(function () {
                  swal("Please Provide All Valid Message Information!");
                  return true;
              });
          });

I will much greatfull to you if you could help me solve this problem.

Regards
SMHasnain
Posted
Comments
manak chand 25-Feb-15 2:41am    
have you installed sweetalert in visual studio..
masterfang 25-Feb-15 6:17am    
yes sir I included both css and js file into the vs project and also included it in the page.
Rajesh Kariyavula 25-Feb-15 8:39am    
Instead of Page reference give Button reference and button type and try

1 solution

Thanks to all I found a solution for my problem, I just to close the button in update pannel and use a scriptmansger over it.

XML
<script type="text/javascript">

        function Showalert() {
            $('#innerMsgDiv').css({ "display": "block" });
            $('#innerMsgDiv').addClass('animated flipInY');
        }

    </script>


XML
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                           
                           <asp:Button class="pull-right btn btn-info" ID="btnSendM" runat="server" Text="Send Message" CausesValidation="False" />
                        </ContentTemplate>
                    </asp:UpdatePanel>



VB
Protected Sub btnSendM_Click(sender As Object, e As EventArgs) Handles btnSendM.Click
        If txtName.Text = "Enter Name" Or txtName.Text = "" Or _
            txtEmail.Text = "Enter Email" Or txtEmail.Text = "" Or _
            txtPhone.Text = "Enter Phone Number" Or txtPhone.Text = "" Or _
            txtMessage.Text = "Enter Your Message." Or txtMessage.Text = "" Then
            'btnHidden_Click(sender, e)
            msgDisplay()
        Else
            contactClass.sendMessage(txtName.Text, txtEmail.Text, txtPhone.Text, txtMessage.Text)
            txtName.Text = "Enter Name"
            txtEmail.Text = "Enter Email"
            txtPhone.Text = "Enter Phone Number"
            txtMessage.Text = "Enter Your Message."
        End If

    End Sub

    Private Sub msgDisplay()
        ScriptManager.RegisterStartupScript(Me, [GetType](), "displayalertmessage", "Showalert();", True)
    End Sub


End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900