Does anyone know how to use button1.attributes.Remove method. I can not get it to remove the onclick event in my button.
This button has its causevalidation=True and I want to add a confirmation box when the button is clicked. .Net adds an onclick event to this button so it can validate. If I use an attributes.add method it will add another onclick event which will be ignored. I want to remove it then use the button1.attributes.add method to add the onclick method that calls a javascript function I wrote. This function will display the confirmation and still validate using the validation control.
Part of my code.
<asp:button id="saveIt" runat="server" Text="Insert New"></asp:button><FONT face="Arial Black">
sScript = "function ValConfirm()" & vbCrLf
sScript += "{" & vbCrLf
sScript += vbTab & "var valid = true;" & vbCrLf
sScript += vbTab & "if(typeof(Page_ClientValidate) == function)" & vbCrLf
sScript += vbTab & "{" & vbCrLf
sScript += vbTab & vbTab & "valid = Page_ClientValidate();" & vbCrLf
sScript += vbTab & "}" & vbCrLf
sScript += vbTab & "if(valid)" & vbCrLf
sScript += vbTab & "{" & vbCrLf
sScript += vbTab & vbTab & "return confirm(Are you sure you want to insert the new record?);" & vbCrLf
sScript += vbTab & "}" & vbCrLf
sScript += vbTab & "else" & vbCrLf
sScript += vbTab & "{" & vbCrLf
sScript += vbTab & vbTab & "return false;" & vbCrLf
sScript += vbTab & "}" & vbCrLf
sScript += "}" & vbCrLf
If (Not IsClientScriptBlockRegistered("MyScript")) Then
RegisterClientScriptBlock("MyScript", sScript)
End If
saveIt.Attributes.Remove("onclick") Heres my problem
saveIt.Attributes.Add("onClick", "ValConfirm();")
Thanks,
James
This button has its causevalidation=True and I want to add a confirmation box when the button is clicked. .Net adds an onclick event to this button so it can validate. If I use an attributes.add method it will add another onclick event which will be ignored. I want to remove it then use the button1.attributes.add method to add the onclick method that calls a javascript function I wrote. This function will display the confirmation and still validate using the validation control.
Part of my code.
<asp:button id="saveIt" runat="server" Text="Insert New"></asp:button><FONT face="Arial Black">
sScript = "function ValConfirm()" & vbCrLf
sScript += "{" & vbCrLf
sScript += vbTab & "var valid = true;" & vbCrLf
sScript += vbTab & "if(typeof(Page_ClientValidate) == function)" & vbCrLf
sScript += vbTab & "{" & vbCrLf
sScript += vbTab & vbTab & "valid = Page_ClientValidate();" & vbCrLf
sScript += vbTab & "}" & vbCrLf
sScript += vbTab & "if(valid)" & vbCrLf
sScript += vbTab & "{" & vbCrLf
sScript += vbTab & vbTab & "return confirm(Are you sure you want to insert the new record?);" & vbCrLf
sScript += vbTab & "}" & vbCrLf
sScript += vbTab & "else" & vbCrLf
sScript += vbTab & "{" & vbCrLf
sScript += vbTab & vbTab & "return false;" & vbCrLf
sScript += vbTab & "}" & vbCrLf
sScript += "}" & vbCrLf
If (Not IsClientScriptBlockRegistered("MyScript")) Then
RegisterClientScriptBlock("MyScript", sScript)
End If
saveIt.Attributes.Remove("onclick") Heres my problem
saveIt.Attributes.Add("onClick", "ValConfirm();")
Thanks,
James