troubleshooting Question

Explain solution :Code does a postback even tho Javascript returns false

Avatar of Camillia
CamilliaFlag for United States of America asked on
JavaScriptASP.NET
11 Comments1 Solution493 ViewsLast Modified:
This is the solution (seems like it) to my issue below but I dont know how to implemet it. If you scroll down, the developer explains a hidden field
http://forums.asp.net/t/1789189.aspx/1



I have the code below and I put "alert" and I get "false" when I cancel the popup msg. It should just cancel and not call the code but not sure why it's calling the code. This is what I have:

protected void lvOutgoing_OnItemDataBound(object sender, ListViewItemEventArgs e)
    { 
        ....
        chkResponseLetter.Attributes.Add("onclick", "rdoClick(" + lblPatientId.Text + "," + lblToHCProvider.Text + ")");
    } 

CheckBox

<asp:CheckBox runat="server" AutoPostBack="true"  OnCheckedChanged="chkResponseLetter_checked" title="Check if you have received a Response letter"  ID="chkResponseLetter" />

Javascript

<script type="text/javascript">
         function rdoClick(click, toHCProviderId) {
                         var msg = confirm("Have you verified you have received the Response letter?");
             alert(msg); //*** I get false here

             if (msg) {//if yes Clicked

                // do whatever

                 return true;
             }
             else
                 return false;

             
         }

    </script>

I tried this but with this...when user clicks on cancel...there's no post back. BUT, it breaks the "ok" functionality. Even when OK is clicked, there's no post back but there should be when user clicks ok

chkResponseLetter.Attributes.Add("onclick", "return rdoClick(" + lblPatientId.Text + "," + lblToHCProvider.Text + ")");
ASKER CERTIFIED SOLUTION
Camillia

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros