0

I have an asp.net application. I am displaying a confirmation popup alert when the selected index changes to a specific value ("Cancelled") in dropdown list.

<asp:DropDownList ID="ddlStatus" runat="server" CssClass="selectstyle" DataTextField="Name" DataValueField="ID" onchange="GetSelectedItem(this)" />

The dropdown has 4 values - "Pending", "Fixed", "Responded" and "Cancelled"

So when user selects "Cancelled" value, I am displaying a confirmation popup box. Depending on the user selection from the confirmation box, I am modifying the UI of the page and update the changes (submit button works).

function GetSelectedItem(x) {
        if (x.value == 4) {
            if (confirm("Are you sure you want to cancel support ticket ?") == true) {
                document.getElementById("lbl_CancellationReason").style.display = 'block';
                document.getElementById("tbx_CancellationReason").style.display = 'block';
            }
        }
        else {
            document.getElementById("lbl_CancellationReason").style.display = 'none';
            document.getElementById("tbx_CancellationReason").style.display = 'none';
            //document.getElementById('<%= btnSubmit.ClientID %>').click();
            $('btnSubmit').trigger('click'); 
        }
    }

But when user selects any other value from the dropdown list ("Pending", "Fixed", "Responded") or makes any other changes in the page, my submit button (update) is not working. It does not give any error but nothing happens on my page.

Here is my cancellation reason and update button,

<td class="label" align="right">
    <div id="lbl_CancellationReason" runat="server" style="display:none">
     Cancellation Reason :
     </div>
</td>
<td>
     <div id="tbx_CancellationReason" runat="server" style="display:none">
       <asp:TextBox ID="tbxCancellationReason" runat="server" CssClass="selectstyle" TextMode="MultiLine" Width="400" Height="50">  </asp:TextBox>                                       
       <asp:RequiredFieldValidator ErrorMessage="Please enter cancellation reason." ValidationGroup="CancellationReason" ControlToValidate="tbxCancellationReason" runat="server" />
    </div>
</td>

<asp:Button ID="btnSubmit" runat="server" Text="Update Details" Style="display: inline; margin-left: 15px;" OnClick="btnUpdate_Click" CssClass="selectstyle" UseSubmitBehavior="false" ValidationGroup="CancellationReason"/>

Not sure what to do.

5
  • When you change DropDownList you call onchange="GetSelectedItem(this) but there is no call for the button. What do you mean when saying "submit button is not working"? Commented Feb 12, 2015 at 20:31
  • When GetSelectedItem(this) is called, I am making a label and a textbox visible, user enters something in the textbox, updates the information and then the button works at that time. But when the value is not "Cancelled" then GetSelectedItem(this) goes in the else part. After that the submit button does not get fired. Commented Feb 12, 2015 at 20:40
  • It does not get fired when user clicks on it? If true, you need to check CancellationReason - maybe it checks and does not let to submit the form. Commented Feb 12, 2015 at 20:43
  • No. I also added the following code, //document.getElementById('<%= btnSubmit.ClientID %>').click(); $('btnSubmit').trigger('click'); but neither option fires the click event. Commented Feb 12, 2015 at 20:44
  • Please modify your post and add code for trigger('click'); Currently it is not clear where you call it. Also either check CancellationReason or share it too as it might be the reason of the issue. Commented Feb 12, 2015 at 20:46

1 Answer 1

0

Use selector by id, not by name

$('#btnSubmit').trigger('click');

--or--

$('#btnSubmit').click();

jquery selector not working, why?

P.S.

Additionally you check for ValidationGroup="CancellationReason" and even the textbox is not visible, the form is not valid and you cannot submit it. To solve it,

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

2 Comments

Did you include jquery?
Yes. <script src="code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>

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.