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. Text Changed and javascript confirm box

Text Changed and javascript confirm box

Scheduled Pinned Locked Moved ASP.NET
questionjavascript
4 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.
  • G Offline
    G Offline
    gbabu17
    wrote on last edited by
    #1

    I have a textbox which is created dynamically in page_load. TextBox tb = new TextBox(); tb.id = "ID1"; tb.text = GetfromDB(); tb.TextChanged +=new EventHandler(tb_TextChanged); Now i want to add a javascript confirmbox as tb.Attributes.Add("onchange","javascript:return confirm('Data has Changed. Click OK To Continue');"); If the user clicks ok then continue to tb_TextChanged function and if user clicks cancel i want to restore the previous value of textbox. How can i write the javascript function? Thanks

    A 1 Reply Last reply
    0
    • G gbabu17

      I have a textbox which is created dynamically in page_load. TextBox tb = new TextBox(); tb.id = "ID1"; tb.text = GetfromDB(); tb.TextChanged +=new EventHandler(tb_TextChanged); Now i want to add a javascript confirmbox as tb.Attributes.Add("onchange","javascript:return confirm('Data has Changed. Click OK To Continue');"); If the user clicks ok then continue to tb_TextChanged function and if user clicks cancel i want to restore the previous value of textbox. How can i write the javascript function? Thanks

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Basically when a postback occurs, everything in the page gets recreated again. If it is not posted back you need to somewhere hold the initial values and show to the items. You can make a global object say

      var myarray = {};
      myarray["textbox1"] = document.getElementById("textbox1").value;
      ..
      ..
      ..

      When you restore, set the value from myarray to actual controls.

      document.getElementById("textbox1").value = myarray.textbox1;
      ...
      ...
      ...

      what is the problem with that. If the page is not posted back you can do this easily. :thumbsup:

      Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


      My Latest Articles-->** Microsoft Bing MAP using Javascript
      CLR objects in SQL Server 2005
      Uncommon C# Keywords
      /xml>

      G 1 Reply Last reply
      0
      • A Abhishek Sur

        Basically when a postback occurs, everything in the page gets recreated again. If it is not posted back you need to somewhere hold the initial values and show to the items. You can make a global object say

        var myarray = {};
        myarray["textbox1"] = document.getElementById("textbox1").value;
        ..
        ..
        ..

        When you restore, set the value from myarray to actual controls.

        document.getElementById("textbox1").value = myarray.textbox1;
        ...
        ...
        ...

        what is the problem with that. If the page is not posted back you can do this easily. :thumbsup:

        Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


        My Latest Articles-->** Microsoft Bing MAP using Javascript
        CLR objects in SQL Server 2005
        Uncommon C# Keywords
        /xml>

        G Offline
        G Offline
        gbabu17
        wrote on last edited by
        #3

        I do not want to store values without any event. I have many textboxes and i want to store the inital value only based on some event. Is there some event like onfocus or onkeydown for the textbox where i can store only for the textbox which is supposed to be changed. Thanks

        A 1 Reply Last reply
        0
        • G gbabu17

          I do not want to store values without any event. I have many textboxes and i want to store the inital value only based on some event. Is there some event like onfocus or onkeydown for the textbox where i can store only for the textbox which is supposed to be changed. Thanks

          A Offline
          A Offline
          Abhishek Sur
          wrote on last edited by
          #4

          of course there is. You might use onfocus = "javascript:myarray[this.id]=this.value" to initialize myarray with initial value if you want. No big deal, do it whatever you feel like. :rose:

          Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


          My Latest Articles-->** Microsoft Bing MAP using Javascript
          CLR objects in SQL Server 2005
          Uncommon C# Keywords
          /xml>

          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