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. Texbox is not Clear On Postback

Texbox is not Clear On Postback

Scheduled Pinned Locked Moved ASP.NET
javascripttoolshelptutorialquestion
5 Posts 4 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.
  • A Offline
    A Offline
    alaminfad
    wrote on last edited by
    #1

    Ive an Obout calender that i change its datemin , datemax according to Dropdownlist selected item, i want the textbox (that the calender copy its value to ) to be clear(empty) when the DDL changes for the user to select a new date ,DDl is AutoPostback true ,ive tried this in the [ddlVacationTypes_SelectedIndexChanged]: TextBox1.Text = "" 'Didnt work the textbox is holding the last value i also tried this in the [Page_Load]: Page.RegisterClientScriptBlock("MyScript", _ "<script language=javascript>" & _ " document.getElementByID('TextBox1').value = '' ; </script>") 'Didnt work the textbox is holding the last value what am i doing wrong? + How to fix this? thXs

    G C A 3 Replies Last reply
    0
    • A alaminfad

      Ive an Obout calender that i change its datemin , datemax according to Dropdownlist selected item, i want the textbox (that the calender copy its value to ) to be clear(empty) when the DDL changes for the user to select a new date ,DDl is AutoPostback true ,ive tried this in the [ddlVacationTypes_SelectedIndexChanged]: TextBox1.Text = "" 'Didnt work the textbox is holding the last value i also tried this in the [Page_Load]: Page.RegisterClientScriptBlock("MyScript", _ "<script language=javascript>" & _ " document.getElementByID('TextBox1').value = '' ; </script>") 'Didnt work the textbox is holding the last value what am i doing wrong? + How to fix this? thXs

      G Offline
      G Offline
      Gamzun
      wrote on last edited by
      #2

      You might be setting it up on page_load :S

      Please don't forget to mark 'Good Answer', if you find it really a good one! Kashif

      1 Reply Last reply
      0
      • A alaminfad

        Ive an Obout calender that i change its datemin , datemax according to Dropdownlist selected item, i want the textbox (that the calender copy its value to ) to be clear(empty) when the DDL changes for the user to select a new date ,DDl is AutoPostback true ,ive tried this in the [ddlVacationTypes_SelectedIndexChanged]: TextBox1.Text = "" 'Didnt work the textbox is holding the last value i also tried this in the [Page_Load]: Page.RegisterClientScriptBlock("MyScript", _ "<script language=javascript>" & _ " document.getElementByID('TextBox1').value = '' ; </script>") 'Didnt work the textbox is holding the last value what am i doing wrong? + How to fix this? thXs

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        Have you stepped through the debugger ? If you're using a third party control, perhaps it is what sets the value ?

        alaminfad wrote:

        " document.getElementByID('TextBox1').value = '' ; ")

        That won't work. Perhaps if you used the right client side ID, it might.

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        1 Reply Last reply
        0
        • A alaminfad

          Ive an Obout calender that i change its datemin , datemax according to Dropdownlist selected item, i want the textbox (that the calender copy its value to ) to be clear(empty) when the DDL changes for the user to select a new date ,DDl is AutoPostback true ,ive tried this in the [ddlVacationTypes_SelectedIndexChanged]: TextBox1.Text = "" 'Didnt work the textbox is holding the last value i also tried this in the [Page_Load]: Page.RegisterClientScriptBlock("MyScript", _ "<script language=javascript>" & _ " document.getElementByID('TextBox1').value = '' ; </script>") 'Didnt work the textbox is holding the last value what am i doing wrong? + How to fix this? thXs

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

          And also before you run a script check if the script block is already exists in the page.Do like this :

          if(!this.ClientScript.IsClientScriptBlockRegistered("MyScript"))
          {
          Page.RegisterClientScriptBlock("MyScript","" & _
          " document.getElementByID('" + TextBox1.ClientId +"').value = '' ; ")
          }

          Also make sure you are not doing this every time the page is posted back. Always check :

          if(this.IsPostBack)
          {
          }

          inside Page_Load Finally, if you make TextBox as serverside, you can set the value inside ddlVacationTypes_SelectedIndexChanged by just calling TextBox1.Text = ddlVacationTypes.SelectedValue It must work. :)

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


          My Latest Articles-->** Simplify Code Using NDepend
          Basics of Bing Search API using .NET
          Microsoft Bing MAP using Javascript

          A 1 Reply Last reply
          0
          • A Abhishek Sur

            And also before you run a script check if the script block is already exists in the page.Do like this :

            if(!this.ClientScript.IsClientScriptBlockRegistered("MyScript"))
            {
            Page.RegisterClientScriptBlock("MyScript","" & _
            " document.getElementByID('" + TextBox1.ClientId +"').value = '' ; ")
            }

            Also make sure you are not doing this every time the page is posted back. Always check :

            if(this.IsPostBack)
            {
            }

            inside Page_Load Finally, if you make TextBox as serverside, you can set the value inside ddlVacationTypes_SelectedIndexChanged by just calling TextBox1.Text = ddlVacationTypes.SelectedValue It must work. :)

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


            My Latest Articles-->** Simplify Code Using NDepend
            Basics of Bing Search API using .NET
            Microsoft Bing MAP using Javascript

            A Offline
            A Offline
            alaminfad
            wrote on last edited by
            #5

            Unfortunately it did'nt work ,i do want this every time the page is posted back , i mean when the user select from the DDL the textbox1 should be empty for him(user) to notice and select a date from the Obout calender image , i tried it both ways(if and if not is post back) it didnt work , i found this property Clear() on the Obout tutorials : ************************************************** If you need to clear the current selected date simply call the method Clear. Example: <obout:Calendar runat="server" id="myCal"> </obout:Calendar> <a onclick="myCal.Clear();"> Clear </a> *********************************************** by the way ive two page loads one page_load in the user control where the DDl and obout Calender and of course its Textbox which we want to clear Second page_load in the actual default page so ive tried to use that property in both page_loads it didnt work ,i have follwed the debugger it going in the right way , here is the code ----------------------------- Dim script As New StringBuilder ' Dim reader As StreamReader = File.OpenText(Server.MapPath(includeFilePath)) If Not Page.ClientScript.IsClientScriptBlockRegistered("MySript") Then 'script.Append(reader.ReadToEnd.Replace("{title}", Me.Title).Replace("{buttonLabel}", Me.ButtonLabel)) ' delay alert 1 ms to handle postback script.Append("<script language='javascript'>document.dfghsdfggetElementByID('Calendar1').Clear();</script>") Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "MySript", script.ToString) End If -------------------------------------------------------------------- one more thing the server doesnt seem to validate what inside the script even if write Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "MySript","Nothing") what is a problem? + how to fix it?

            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