开发者

jQuery works, then it doesn't anymore

I have a function in my main to load a dialog box:

<a href="#" class="insert" onclick="return openDialog('AddEditUser.aspx',350);">Add new</a>

This works because all the jquery script are loaded at the start of the main and I have defined the openDialog function.

But inside 'AddEditUser.aspx', the page that is opened, there is this code to close the dialog box at the end:

string script = @"jquery('#dialog').html('');jquery('#dialog').dialog('destroy');window.location.reload()";
ScriptManager.RegisterClientScriptBlock(this, typeof(UpdatePanel), "jscript", scri开发者_如何学JAVApt, true);

And when I run the program, I always get the error "Runtime-error Microsoft JScript: Object expected" at this last jquery code sequence.

I googled the error and it says you get this because jquery isn't loaded but it is because the dialog box opened. What is the cause of this error?


What does openDialog do? I believe it opens a new window and loads the page you pass to it. Are you sure you have jQuery on the new page(AddEditUser.aspx) you are trying to open? I see the issue is because it is not finding jQuery in the new page.

Also you shouild wrap the inline js in $(function(){})just to ensure that dom is ready and#dialogis available tojQuery`. Try this

string script = @"jquery(function(){jquery('#dialog').html('');jquery('#dialog').dialog('destroy');window.location.reload();});";
ScriptManager.RegisterClientScriptBlock(this, typeof(UpdatePanel), "jscript", script, true);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜