Problem with enabling button via javascript in .js file RRS feed

  • Question

  • User2001833234 posted

    Could someone please help:

         I have a main page with two buttons in an "Update Panel".  button1 via a javascript function in an external script.js file causes a popup window to appear and the user then can select a part number. 

    script.js // functions

    function SelectProducts(URL, ctrlText, ctrlBtn, width, height)
        var path = URL + "?date=" + (new Date()).getTime();
        var WinSettings = "center:yes;resizable:no;dialogHeight:" + height + "px;dialogWidth:" + width + "px;scroll:no"
        var returnArg = window.showModalDialog(path, '', WinSettings);

        if (returnArg != "") {
            document.getElementById(btnsave).disabled = false;

            /* ctrlBtn.disabled = fasle; */
        UpdateProdText(ctrlText, returnArg);

    function UpdateProdText(ctrlText, arg) {
              ctrlText.value = arg;

    Once the user closes the popup window the  following code returns the product id that the user selected. to the calling javascript function SelectProducts in script.js

    *************************in popup.aspx******************************************

    window.onunload = unloadPage;
    function unloadPage() {
      window.returnValue = document.getElementById('<%=txtProd.ClientID%>').value;


    Once the execution returns to the funtion SelectProducts() in script.js I take the return productid string and test if it's populated or empty, if it's populated, I want to enable a button.  Here is where the problem occurs.  I have tried two ways to enable the button and both execute without error but leave the button2 disabled on my Main.aspx form.

    method one is I have attached the following function call to the button1_Load method in my Main.aspx code behind file.  I pass a textbox that I want the selected prodid populated with and the id of the button that I want to enable.

     protected void button1_Load(object sender, EventArgs e)
                button1.OnClientClick = "SelectProducts('SelectProd.aspx'" + "," + txtPostProd.ClientID.ToString() + "," + button2.ClientID.ToString() + "," +
                                                      "'820px'" + "," + "'340px'" + ");";

    I have tried both using the control id which I set in Main.aspx  using <script type="text/javascript"> btnsave = '<%=button2.ClientID %>';  </script> to enable the button "document.getElementById(btnsave ).disabled = false;" and I have tried using  the passed controlid "ctrlBtn.disabled = false;" and both fail to change the enabled state of the button on the UpdatePanel.  Note:  Neither method causes a javascript error but when I try alert(ctrlBtn.disabled) or alert(document.getElementById(btnsave ).disabled) I do get a message stating that the control is nothing.

    Also, I am able to set the text of the passed textbox control to the text selected via the value returned from the popup.  That textbox is in the same updatepanel as the button2.

    Would anyone know what I'm doing wrong.

    Tuesday, November 12, 2013 1:06 PM


  • User2001833234 posted

    I solved this by simply adding code behind to test the textbox.Text, in the button1.Click event and enabling button2 if there was text in the textbox.Text.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 12, 2013 4:50 PM