Texbox is not Clear On Postback
-
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
-
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
-
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
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.
-
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
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 insideddlVacationTypes_SelectedIndexChanged
by just callingTextBox1.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 -
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 insideddlVacationTypes_SelectedIndexChanged
by just callingTextBox1.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 JavascriptUnfortunately 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?