Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing Client Side Script after Controls Have Changed

Status
Not open for further replies.

Quanita

Programmer
Aug 30, 2001
7
AU
Hi,
I have an aspx page developed in Visual Studio 2003, which has a validate function which returns true/false

When a user wants to add an entry to the database, I call the validate function, set labels to red on textboxes/listboxes/dropdownlists that have not been properly populated or selected and produce a client side alert to let the user know that there is a problem with the fields entered

Code:
Private Sub btnCreateReportEntry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateReportEntry.Click
        If ValidateReportEntry() = False Then
            RegisterClientScriptBlock("showCreateReportMessage", "<script language=""JavaScript""> alert('You need to rectify all fields in Red before adding a Report Entry!'); </script>")
        Else
            'code to insert into db here
        End If
    End Sub

This works fine, however, after changing all the fields back to correct values, and I click the button again, it displays the alert again and doesnt go into the ValidateReportEntry() function to check that the fields are valid.

I suspect that the page isnt being refreshed properly and the client side script is being run over and over again

How do I remove it? or Force the page to be rebuilt without the client side script?

Thanks
Quanita
 
You'll either have to build the logic into your javascript function so that it is only run (or called) when necessary.

Alternatively, if you wanted to remove the script from the page, consider placing it into a Literal control rather than using the RegisterClientScriptBlock method and then you can just delete the control or remove it's Text.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Can you just use the built in validation framework? It's very robust and you'll save yourself a lot of time and effort.

MCP, MCTS - .NET Framework 2.0 Web Applications
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top