Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with ScriptManager.RegisterClientScriptBlock and jQuery in Internet Explorer 8

I want to use jGrowl plugin for jQuery (http://stanlemon.net/projects/jgrowl.html#samples) to display some messages on a page. To do this, I call the ScriptManager.RegisterClientScriptBlock method like this:

ScriptManager.RegisterClientScriptBlock(this, typeof(Page), Guid.NewGuid().ToString(),
   "$.jGrowl('" + message + "');", true);

The code works perfect in Firefox/Chrome/Safari. However in Internet Explorer I don't see the notification and I don't get any Javascript error.

I work under Windows 7 and I have Internet Explorer 8 Beta (version 8.0.7000.0) and I have the same "bug" under Compatibility Mode.

How can I solve this problem?

like image 639
Stefan Filip Avatar asked May 09 '09 20:05

Stefan Filip


2 Answers

This problem occurs because IE8 expects all the DOM elements to be loaded before modifications to the DOM can be made. I was able to duplicate the problem you described with jGrowl.

To fix it, I just modified your script so that the call to jGrowl happens once the document is ready. Here's the updated code:

ScriptManager.RegisterClientScriptBlock(this, typeof(Page), 
     Guid.NewGuid().ToString(),
     "$(function(){$.jGrowl('" + message + "');});", true);
like image 172
Jose Basilio Avatar answered Nov 12 '22 10:11

Jose Basilio


add <form runat="server" id="form1"> to page. It will work...

like image 38
Ugur CAN Avatar answered Nov 12 '22 08:11

Ugur CAN