简体   繁体   English

asp.net javascript .click()事件未在服务器上触发

[英]asp.net javascript .click() event not firing on server

I have the following code which is working fine on the development machine. 我有以下代码在开发机器上正常工作。 But, when I deploy it to IIS, the .click() does not fire. 但是,当我将其部署到IIS时, the .click()不会触发。

  1. I have drop down box, when a status is selected, I add the following code to open up a RadWindow 我有下拉框,当选择状态时,我添加以下代码以打开RadWindow

     if (ddlStatusID.SelectedValue.ToString() == "2") btnUpdateStatus.Attributes.Add("onclick", "return OpenWindow2('" + ResolveUrl("~/Request/AddBillableTime.aspx? RequestId=" + RequestId.ToString()) + "','650','320');"); else btnUpdateStatus.Attributes.Add("onclick", ""); 
  2. In the popup page, when the user clicks on a button I add do the following 在弹出页面中,当用户点击我添加的按钮时,请执行以下操作

     ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", "ClosePopup();", true); 

This is the ClosePopup javascript. 这是ClosePopup的javascript。

function ClosePopup() {
    //debugger;
    alert('This is before closing the window');
    var oWindow = GetRadWindow();
    oWindow.argument = null;
    oWindow.close();
    alert('This is after closing the window');
    oWindow.BrowserWindow.ButtonClick();
    }
  1. In the main window, I have following javascript, which is invoked in the last line of the above javascript. 在主窗口中,我有以下javascript,它在上面的javascript的最后一行中调用。

     function ButtonClick() { //debugger; alert('This is before button click!'); var btnUpdateStatus = document.getElementById('ctl00_ContentPlaceHolder1_btnUpdateStatus'); alert('This is getting the button!'); btnUpdateStatus.setAttribute("onclick", ""); alert('This is setting the button!'); btnUpdateStatus.click(); alert('This is after clicking the button!'); 

    } }

I have used the alerts to check how far the javascript function is executed. 我已经使用警报来检查javascript函数执行的程度。

The entire functionality is working fine when I run it using Visual Studio and also when I host it in my local IIS server. 当我使用Visual Studio运行它时,以及当我在本地IIS服务器中托管它时,整个功能正常工作。 But, when I deploy it to the server, the click() event stops firing. 但是,当我将其部署到服务器时,click()事件将停止触发。

Please let me know if there is anything wrong in the code. 如果代码中有任何错误,请告诉我。

I didn't had time to look into this issue for some as I was assigned to a new task. 当我被分配到一项新任务时,我没有时间研究这个问题。 But had to fix it once I was back in the same task. 但是一旦我回到同一个任务中就不得不修复它。 I got some help from a friend of mine to fix the issue. 我从我的一个朋友那里得到了一些帮助来解决这个问题。 I had to change the current logic a bit and have explained the solution below. 我不得不稍微改变当前的逻辑,并解释了下面的解决方案。

I changed the ButtonClick function as below to create a manual post back to the page using the __doPostBack function. 我更改了ButtonClick函数,如下所示,使用__doPostBack函数创建一个返回页面的手动帖子。

function ButtonClick() {
__doPostBack('btnUpdatePage', '');
return;
}

I handled the post back from the Page_Load method of the page. 我从页面的Page_Load方法处理了帖子。

if (Request["__EVENTTARGET"] == "btnUpdatePage")
{
     UpdateStatus();
}

If the post back event target matches the assigned event target from the __doPostBack method, then I called a method to update the status. 如果回发事件目标与__doPostBack方法中指定的事件目标匹配,那么我调用了一个方法来更新状态。

This way I could avoid the issue. 这样我就可以避免这个问题。 But I do not know why the event was not fired using the old ButtonClick function. 但我不知道为什么事件没有使用旧的ButtonClick函数触发。

If the code works fine on your PC, the only thing that looks fishy to me are these 2 lines: 如果代码在您的PC上正常工作,那么对我来说唯一可疑的就是这两行:

1. document.getElementById('ctl00_ContentPlaceHolder1_btnUpdateStatus');

2. btnUpdateStatus.setAttribute("onclick", "");

For the first line , you should be doing this, instead: 对于第一行,您应该这样做,而不是:

document.getElementById('<%=btnUpdateStatus.ClientID%>');

And for the second line, it seems that you are setting the onclick handler to "" which basically shouldn't do anything. 对于第二行,似乎您将onclick处理程序设置为"" ,基本上不应该执行任何操作。

It may not be the problem at all. 这根本不是问题。 The best thing to do is debug it with Firebug, putting a breakpoint in the appropriate Javascript functions that are being called. 最好的办法是使用Firebug调试它,在正在调用的相应Javascript函数中放置一个断点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM