0

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.

  1. I have drop down box, when a status is selected, I add the following code to open up a 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.

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.

    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.

The entire functionality is working fine when I run it using Visual Studio and also when I host it in my local IIS server. But, when I deploy it to the server, the click() event stops firing.

Please let me know if there is anything wrong in the code.

2 Answers 2

2

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.

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

I handled the post back from the Page_Load method of the page.

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.

This way I could avoid the issue. But I do not know why the event was not fired using the old ButtonClick function.

Sign up to request clarification or add additional context in comments.

Comments

0

If the code works fine on your PC, the only thing that looks fishy to me are these 2 lines:

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.

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.

1 Comment

Hi I have done as you suggested but it gives the following error. The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). But I replaced the = with # and could get rid of the error. But still the problem exists when deployed. I used some alerts to determine up to what place the code is executed and found that the whole Javascript is executed. But, the button click method is not invoked. Please help.

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.