开发者

How to declare Popup message in the site.Master page for My Entire Application using Jquery?

I need to show the same popup message throwout my entire application like showing success message failure message? Pl开发者_如何转开发ease wait Message? to my Entire application..

in my application If I click any save if its taking some time I need to show Please wait pop up message while loading the page..

Can any body help me out how to declare in site.master page this? using jquery

thanks


You will just want to define some functions in your master page and call them where appropriate.

Lets add a div to your master page.

     <div id="messageDisplay">
     </div>

You will of course want to style the message with css and position the DIV where you really want it.

// Display success message.
function successMessage()
{
     $('#messageDisplay').text('Your operation was successful!').slideDown();
}

Or define a function where you can pass in the message you want to display.

// Display message.
function displayMessage(messageText)
{
     $('#messageDisplay').text(messageText).slideDown();
}

I prefer the second method so you only define one function and just pass a string to it whenever you call it.

To hide the message define a hide function.

// Hide currently displayed message.
function hideMessage()
{
     $('#messageDisplay').slideUp();
}

Then in your pages just call the functions. Pretend you have an ajax operation that is going to take a long time. First it will display "Please wait..." and then "Successful!" when done.

$('#someButton').click(function ()
{
     hideMessage();
     displayMessage("Please wait...");
     $.ajax(
     {
          url: "some/url/for/ajax/function",
          data: { someData: "some data" },
          type: "POST",
          success: function (response)
          {
               hideMessage();
               displayMessage("Successful!");
          },
          error: function (xhr, textStatus, errorThrown)
          {
               hideMessage();
               displayMessage(textStatus);
          }
     });
});

EDIT: Remember that when a page inherits from a master page, the browser sees it as one page altogether. So any javascript defined on the master page will be included as part of every page from that point forward, which means that even page-specific scripts could reference functions defined in the master page just fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜