0

I have JQuery function shows notification message. From my asp.net page I want to call it when page gets fully loaded e.g when: Request.QueryString[c_opID] != null; I tried to call the function from Page_Load and Page_LoadComplete using ScriptManager.RegisterStartupScript() but the function doesn't fire up. On other hand, when I call it on button click it does what should be done.

JQuery Function:

function showMessage(title, message) {
    PNotify.prototype.options.styling = "jqueryui";
    var notice = new PNotify({
        title: title,
        text: message,
        type: 'success',
        opacity: 1,
        animate_speed: 'fast',
        addclass: 'custom'
    });
    notice.get().click(function() {
        notice.remove();
    });
    setTimeout(function() {
        notice.remove();
    }, 3000);
}

Asp.Net code behind call:

            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", @"showMessage('" + title + "','" + message + "');", true);
Mhdali
  • 690
  • 7
  • 17
  • 1
    can you show us the code you used to load this script on the page? Also the script itself – Mivaweb Nov 27 '14 at 07:41
  • ScriptManager.RegisterStartupScript(this, this.GetType(), "script", @"PNotify.prototype.options.styling = ""jqueryui""; var notice = new PNotify({title: 'Success!',text: 'Computer has been saved successfully.',type: 'success',opacity: 1,animate_speed: 'fast',addclass: 'custom'});notice.get().click(function() {notice.remove();});setTimeout(function() {notice.remove();}, 3000);", true); – Mhdali Nov 27 '14 at 07:42
  • 2
    Please add it in your question with code tags, this is not readable – Mivaweb Nov 27 '14 at 07:43

1 Answers1

2

Alternative would be pure js

All you need is to get parameter from url with javascript. here is one solution (copied from How can I get query string values in JavaScript? )

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

And then

$(function () {

    if (getParameterByName('your_parameter_name')){
        // show message
    }
})
Community
  • 1
  • 1
maxlego
  • 4,864
  • 3
  • 31
  • 38
  • Great solution, I tried it and it works fine! thanks, the problem in this solution that I have asp.net parameters that I check their values to show different messages, e.g I check the Culture of current thread to show localized messages. – Mhdali Nov 27 '14 at 08:02