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);
3
  • 1
    can you show us the code you used to load this script on the page? Also the script itself Commented Nov 27, 2014 at 7: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); Commented Nov 27, 2014 at 7:42
  • 2
    Please add it in your question with code tags, this is not readable Commented Nov 27, 2014 at 7:43

1 Answer 1

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
    }
})
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.