Error using RegisterClientScriptBlock

S

Steven K

Hello,

I am trying to create a JavaScript function and am getting the following
error: 'jsFormValidation' is not a member of 'ASP.ciJava_aspx'.

Sub Page_Load(Sender As Object, E As EventArgs)
Dim ctrlValidate As String = tbxSubmitter.ID
Dim strFormValidation As String = _
"<script language='javascript'> function jsFormValidation() {" & _
"alert('Please enter your Name in the |Name| field.');" & _
"document.getElementById('" & ctrlValidate & "').focus();}" & _
"<" & "/script>"

If(Not IsClientScriptBlockRegistered("jsFormValidation"))
RegisterClientScriptBlock("jsFormValidation", strFormValidation)
End If
End Sub


In the form:

<td width="100" align="center">
<asp:ImageButton runat="server"
ImageURL="../../images/art_dbflash_go.jpg"
ImageAlign="Middle"
AlternateText="sckeels"
OnCommand="jsFormValidation(this)"
CommandName="ASPNET"/>
</td>
 
K

Kevin Spencer

You're trying to use a client-side JavaScript function to handle a
server-side event.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
G

Guest

Hi Steven

The reason is that OnCommand is a server-side event. How can you call a client-side javascript function through server-side
Please try add this line
Imagebutton1.Attributes("onclick") = "jsFormValidation();
and remove this line
OnCommand="jsFormValidation(this)

Bin Song, MC



Sub Page_Load(Sender As Object, E As EventArgs
Dim ctrlValidate As String = tbxSubmitter.I
Dim strFormValidation As String =
"<script language='javascript'> function jsFormValidation() {" &
"alert('Please enter your Name in the |Name| field.');" &
"document.getElementById('" & ctrlValidate & "').focus();}" &
"<" & "/script>

If(Not IsClientScriptBlockRegistered("jsFormValidation")
RegisterClientScriptBlock("jsFormValidation", strFormValidation
End I
Imagebutton1.Attributes("onclick") = "jsFormValidation();
End Su


In the form

<td width="100" align="center"><asp:ImageButton runat="server
ImageURL="../../images/art_dbflash_go.jpg
ImageAlign="Middle
AlternateText="sckeels
CommandName="ASPNET"/></td>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top