Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72358

Response.Write is not adding a tag to my HTML

$
0
0

I have an ASP.NET WebForms app where I'm generating some HTML code using Response.Write in VB.NET. However I want to add some validation code:

' add jQuery validator for mandatory fields
Response.Write("<script type='text/javascript'>")
Response.Write("mandatoryAdditionalFieldRules = Object.assign(mandatoryAdditionalFieldRules, {")
Dim mandatoryAdditionalFieldsStrings As New List(Of String)
For Each q As String In MandatoryAdditionalFields
    mandatoryAdditionalFieldsStrings.Add(q & ": {required: true}")
Next
Response.Write(String.Join(", ", mandatoryAdditionalFieldsStrings))
Response.Write("});")
Response.Write("</script>")

This is a list of fields that is read by a JavaScript function to make sure that all those fields are filled in:

jQuery("#formEdit").validate({
rules: Object.assign({
    InitialDate: {
        required: true,
        date: true
    },
}, mandatoryAdditionalFieldRules),
messages: {
    InitialDate: "Enter the Initial Date",
}});

My problem is that this script is not being rendered in the output HTML in my browser, and thus the JavaScript code doesn't know to validate the mandatory fields. I stepped through the VB.NET code and I see where it is being called. Why would the JavaScript not appear in my browser when I'm calling Response.Write to write it out? Other content of the page containing this code is being rendered. It's just the JavaScript I added that's not rendering.

edit: could this have something to do with the fact that this page is loaded via an AJAX call?

jQuery('#ClientCareVisitationContactTypeAdditionalFields').load('../AdditionalField/AdditionalFieldDisplayHTMLContactType.aspx', {...}, function(responseTxt, statusTxt, xhr){
    if(statusTxt == "success"){
        // do stuff
    };
    if(statusTxt == "error")
        alert("Error: " + xhr.status + ": " + xhr.statusText);
});

Viewing all articles
Browse latest Browse all 72358

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>