elf
08-11-2009, 10:47 PM
I have a web page that needs to use a .js file with all of the functions in it. The problem I'm having is getting the DropDownList controls to change selectindex = 0. When I run the script using:
Dim str As String
str = "function ClearAllControls() {" _
& "for (i = 0; i <= document.forms[0].length; i++) {" _
& "doc = document.forms[0].elements[i]; alert(doc.name + ' ' + doc.type);" _
& " switch (doc.type) {" _
& " case 'text':doc.value = ''; break;" _
& " case 'textarea':doc.value = ''; break;" _
& " case 'checkbox':doc.checked = false; break;" _
Remove & " case 'select-one':doc.selectedindex = 0; break;" _
& " case 'select-one':doc.Option[0].selected = true; _
& " default:break;}}}"
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "ResetControls", str, True)
it works fine.
But, when I move the function to a .js file and use the following code it fails to reset the DropDownList controls.
Dim csname As String = "ResetControls"
Dim csurl As String = "~/ClientSide_Functions.js"
Dim cstype As Type = Me.GetType()
' Get a ClientScriptManager reference from the Page class.
Dim cs As ClientScriptManager = Page.ClientScript
' Check to see if the include script is already registered.
If (Not cs.IsClientScriptIncludeRegistered(cstype, csname)) Then
cs.RegisterClientScriptInclude(cstype, csname, ResolveClientUrl(csurl))
End If
Can anyone help?:confused:
Dim str As String
str = "function ClearAllControls() {" _
& "for (i = 0; i <= document.forms[0].length; i++) {" _
& "doc = document.forms[0].elements[i]; alert(doc.name + ' ' + doc.type);" _
& " switch (doc.type) {" _
& " case 'text':doc.value = ''; break;" _
& " case 'textarea':doc.value = ''; break;" _
& " case 'checkbox':doc.checked = false; break;" _
Remove & " case 'select-one':doc.selectedindex = 0; break;" _
& " case 'select-one':doc.Option[0].selected = true; _
& " default:break;}}}"
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "ResetControls", str, True)
it works fine.
But, when I move the function to a .js file and use the following code it fails to reset the DropDownList controls.
Dim csname As String = "ResetControls"
Dim csurl As String = "~/ClientSide_Functions.js"
Dim cstype As Type = Me.GetType()
' Get a ClientScriptManager reference from the Page class.
Dim cs As ClientScriptManager = Page.ClientScript
' Check to see if the include script is already registered.
If (Not cs.IsClientScriptIncludeRegistered(cstype, csname)) Then
cs.RegisterClientScriptInclude(cstype, csname, ResolveClientUrl(csurl))
End If
Can anyone help?:confused: