Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. dropdownlist postback

dropdownlist postback

Scheduled Pinned Locked Moved ASP.NET
databasejavascriptsysadminhelptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tuwing Sabado
    wrote on last edited by
    #1

    I have a dropdownlist with a OnSelectedIndexChange event handler which extract data from the database when index change. But before the OnSelectedIndexChange being raise I need to validate the answer of the user on the Confirm dialog box(javascript) which will be shown if the user change the value of the dropdownlist. The answer on the confirm dialogbox will determine, if the dropdownlist will postback or not. But the problem is either I choose OK or Cancel it always raise the OnSelectedIndexChange on the server side that cause the postback. Here's my question How to prevent the dropdownlist to raise a postback if the selected index are 1,2,3,4,5 or the answer to the confirm dialog is Cancel.

    M 1 Reply Last reply
    0
    • T Tuwing Sabado

      I have a dropdownlist with a OnSelectedIndexChange event handler which extract data from the database when index change. But before the OnSelectedIndexChange being raise I need to validate the answer of the user on the Confirm dialog box(javascript) which will be shown if the user change the value of the dropdownlist. The answer on the confirm dialogbox will determine, if the dropdownlist will postback or not. But the problem is either I choose OK or Cancel it always raise the OnSelectedIndexChange on the server side that cause the postback. Here's my question How to prevent the dropdownlist to raise a postback if the selected index are 1,2,3,4,5 or the answer to the confirm dialog is Cancel.

      M Offline
      M Offline
      Manoj Tillu
      wrote on last edited by
      #2

      R u returning boolean value from ur function of javascript? If not do one thing return false from ur javascript function when user choose to cancel. Second thing when u call a javascript function on onindexchange client side event of dropdown call it with return statment. e.g. dropdownlist.attributes.add("OnIndexchange","return fnc();"); all the best Happy Programming Manoj Tillu

      T 1 Reply Last reply
      0
      • M Manoj Tillu

        R u returning boolean value from ur function of javascript? If not do one thing return false from ur javascript function when user choose to cancel. Second thing when u call a javascript function on onindexchange client side event of dropdown call it with return statment. e.g. dropdownlist.attributes.add("OnIndexchange","return fnc();"); all the best Happy Programming Manoj Tillu

        T Offline
        T Offline
        Tuwing Sabado
        wrote on last edited by
        #3

        Yup, I did that but instead of using the OnIndexchange attribute I’ve choose the the OnChange attribute. What is the difference between the two attribute? This code was inside the Page Load Event Handler. This will drop the needed javascript function on page load.

                javascript.Append("");
                javascript.Append("var dropDownListSelectedIndex = -1;");
                javascript.Append("function verify(msg)");
                javascript.Append("{");
                javascript.Append("     var isOK = confirm(msg);");
                javascript.Append("     if (!isOK)");
                javascript.Append("     {");
                javascript.Append("          obj.selectedIndex = dropDownListSelectedIndex;");
                javascript.Append("     }");
                javascript.Append("     return isOK;");
                javascript.Append("}");
                javascript.Append("");
                Page.RegisterStartupScript("dropDownListConfirm", javascript.ToString());
        

        Here's the adding of attribute from dropdownlist.

                Dropdownlist.Attributes.Add("OnChange", "javascript:verify(this)");
        

        Thanks,

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups