Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am using NOTIFY on a html input to notify my user whether the record has been saved or not. and It works just fine. But when I try to use it from my code behind file, it isn't. I understand that javascript is a client side technology and have tried using RegisterStartupScript but no luck.

I am trying to use it on a button click like this

        protected void Button1_Click1(object sender, EventArgs e)
    {
        var script = " $.notify.success('I do not want to close by myself close me ', { close: true });";
        ClientScript.RegisterStartupScript(typeof(Page), "ButtonAlert", script, true);

    }

but no luck.

I am sure there must be a way to show a notification bar on top once the database has been updated. Say can we do it using a function?
my script is defined as follows

 <!-- Notify Implementation -->
<script src="../Scripts/jquery-1.9.0.js" type="text/javascript"></script>
<link href="../Styles/notify.css" rel="stylesheet" type="text/css" />
<script src="../Scripts/notify.js" type="text/javascript" ></script>

<script type="text/javascript">

     function myNotify() {
         $.notify.success('I do not want to close by myself close me ', { close: true });
     };

Can somebody help please

share|improve this question
 
Pls see browser's console to see if there is any error? –  namkha87 Jan 28 at 6:14
 
try to view page source from your browser and see if the script is rendered in there. –  Iswanto San Jan 28 at 6:15
 
@namkha87 no error thrown –  Athar Anis Jan 28 at 6:17
 
@IswantoSan i think it is being rendered here is what i found on page source <input type="submit" name="ctl00$MainContent$Button1" value="Button" onclick="myNotify();WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$MainContent$Button1&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="MainContent_Button1" /> –  Athar Anis Jan 28 at 6:18

3 Answers

try like this:-

  System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.Append("<script language='javascript'>");
                sb.Append("function notify(){");
                sb.Append("$.notify.success('I do not want to close by myself close me ', { close: true });");
    sb.Append("}");
                sb.Append("/script>");

 ClientScript.RegisterStartupScript(typeof(Page), "ButtonAlert", sb, true);
share|improve this answer
 
the browser console throws an exception Uncaught SyntaxError: Unexpected token < –  Athar Anis Jan 28 at 7:17
 
Give Full error detail:- Unexpected token ???.. –  Pranav Jan 28 at 7:21
 
thats what the chrome console shows only .. Uncaught SyntaxError: Unexpected token < –  Athar Anis Jan 28 at 7:22
 
and this error is thrown on line <script type="text/javascript">function notify(){var script = " $.notify.success('I do not want to close by myself close me ', { close: true });"}</script>//]]> –  Athar Anis Jan 28 at 7:22
 
bro... my email is aathar at gmail dot com... send me your email addresss i will give you the remote session so that you can check –  Athar Anis Jan 28 at 7:49
show 3 more comments

Try this :

Page.ClientScript.RegisterStartupScript(this.GetType(),"ButtonAlert","myNotify()",true);
share|improve this answer
 
the browser console throws an exception Uncaught TypeError: Cannot call method 'attr' of undefined –  Athar Anis Jan 28 at 6:32

this resolved my problem as described in HERE. I used a helper class and yooo it solved the issue.

    using System.Web.UI;

public static class NotificationHelper
{
    /// <summary>
    /// Shows the successful notification.
    /// </summary>
    /// <param name="page">The page.</param>
    /// <param name="message">The message.</param>
    public static void ShowSuccessfulNotification(this Page page, string message)
    {
        page.ClientScript.RegisterStartupScript(page.GetType(), "notificationScript",
                                                "<script type='text/javascript'>  $(document).ready(function () {  $.notify.success('I do not want to close by myself close me ', { close: true });});</script>");
    }
}
share|improve this answer
 
i am glad you got the answer .. –  Pranav Jan 28 at 9:41
 
yes... thanks for your help and time bro. i can't mark your answer as solved but would definitely give a up vote. thanks again bro –  Athar Anis Jan 28 at 9:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.