Community discussion forum

LinkButton not calling a javascript function in IE

  • 1 year ago

    Hi Guys,

    I have a linkbutton which calls a .net function which when clicked either displays or hides a DIV and changes an image. I also need this linkbutton to change the property of a javascript boolean variable.

    The javascript in place currently produces a popup notifying users that they have not completed their registration if they try to navigate away from the page without having submitted the form. All I need the linkbutton to do is to submit the following "needToConfirm = false;". By doing so, when the user clicks the linkbutton and the DIV is displayed/hidden (this refreshes the page) the javascript knows not to display the popup box as the user is staying on the page. This works fine in Firefox but not IE.

    I have added this to buttons, which work fine across both browsers, so it only the Linkbutton in IE that I am struggling.

    Below is my code:

    Client Side

    <asp:linkbutton id="lbViewAllProfessions"  runat="server"  önclick="lbViewAllProfessions_OnClick" xmlns:asp="#unknown">
    <asp:image id="imgIcon" runat="server" imageurl="images/general/icon-plus.gif" /> view all job types


    Server Side
    Note: I have included the code for my working buttons below too.

    //This is in my Page_Load

    btnCandidateRegister.Attributes.Add("onClick", "needToConfirm = false;");
    btnFindAddress.Attributes.Add("onClick", "needToConfirm = false;");
    btnOKAddress.Attributes.Add("onClick", "needToConfirm = false;");
    btnCancelAddress.Attributes.Add("onClick", "needToConfirm = false;");
    lbViewAllProfessions.Attributes.Add("onClick", "needToConfirm = false;");
    //.Net function called by LinkButton
    protected void lbViewAllProfessions_OnClick(object sender, EventArgs e)
    {
    if (imgIcon.ImageUrl == "images/general/icon-plus.gif")
    {
    divSkillsBox.Visible = true;
    imgIcon.ImageUrl = "images/general/icon-minus.gif";
    }
    else
    {
    divSkillsBox.Visible = false;
    imgIcon.ImageUrl = "images/general/icon-plus.gif";
    }

    }


    Javascript

    <script language="JavaScript" type="text/javascript">
    var needToConfirm = true;

    window.onbeforeunload = confirmExit;
    function confirmExit()
    {
    if (needToConfirm)
    {
    needToConfirm = false;
    return "Your have not completed your registration process.";
    }else{
    needToConfirm = true;
    return;
    }
    }
    </script>


    I hope this is clear enough. Please let me know if you need anymore info.

    Thanks in advance,
    Martin
  • 1 year ago

    Hi,

    Out of interest, does IE display any javascript errors when the link button is clicked?

    What happens if you put: java scipt:alert('test'); needToConfirm = false; in the attributes.add code?

    Regards

    Simon C

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback