473,381 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,381 software developers and data experts.

button.Attributes.Add does not work after I added Validation control on the page

I use

btnSave.Attributes.Add("onclick", "ShowMessage()")

to link my web control button to a JavaScript function. It
works well until I added a Validation control into the
page. After that, even the all of the validations passed,
my ShowMessage() still does not get triggered. When
checking the view source carefully, I found that the
btnSave button have 2 onClick events defined in the tag.
In this case, only the 1st onClick event (the validation
one) got triggered.

Does anyone know how to fix this problem and let me be
able to run ShowMessage() JavaScript function?
Thanks a lot.

Here is the VB code behind:

Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents btnSave As
Protected WithEvents TextBox1 As
Protected WithEvents RequiredFieldValidator1 As
Protected WithEvents Label1 As

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub

End Sub

Private Sub Page_Init(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web
Form Designer
'Do not modify it using the code editor.
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

btnSave.Attributes.Add("onclick", "ShowMessage()")

End Sub

End Class

Here is the HTML of the ASPX page:

<%@ Page Language="vb" AutoEventWireup="false"
<meta name="GENERATOR" content="Microsoft Visual
Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic
<meta name="vs_defaultClientScript"
<meta name="vs_targetSchema"
<script language="javascript">
function ShowMessage()
alert("test message");
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="Label1" style="Z-INDEX: 101;
LEFT: 51px; POSITION: absolute; TOP: 37px" runat="server"
Width="236px" Height="16px">Simple Test</asp:Label>
<asp:Button id="btnSave" style="Z-INDEX:
102; LEFT: 59px; POSITION: absolute; TOP: 110px"
runat="server" Text="Save"></asp:Button>
<asp:TextBox id="TextBox1" style="Z-INDEX:
103; LEFT: 59px; POSITION: absolute; TOP: 70px"
runat="server" Width="181px" Height="20px"></asp:TextBox>
id="RequiredFieldValidator1" style="Z-INDEX: 104; LEFT:
279px; POSITION: absolute; TOP: 71px" runat="server"
ErrorMessage="Text is required"
ControlToValidate="TextBox1">Please enter something into
the text box.</asp:RequiredFieldValidator>

Nov 20 '05 #1
1 3846
Hi Bruce,

This is only throwing out an idea.

Is it possible to <get> the btnSave's onclick Attribute?
If so, you could add on your "ShowMessage()" and put it back.

Dim Index As Integer
Index = [...get the index of the "onclick" Attribute...]
btnSave.Attributes (Index) &= "; ShowMessage()" 'Note the ';'.

If this fails with a casting error, you may need:
sOnClick As String = DirectCast (btnSave.Attributes (Index), String)
btnSave.Attributes (Index) = sOnClick & "; ShowMessage()" 'Note the ';'.

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Tim Meagher | last post by:
I am trying to use both validation controls and to add submit button attributes, but when I add the button attributes, the javascript fpr the validation controls is no longer created for the page. ...
by: Matt Howeson | last post by:
I am sure this question has been asked many times, however I am yet to find a satisfactory solution to the problem. I have a number of user controls within an asp.net page, a login box, a search...
by: Herve MAILLARD | last post by:
Hi, J'ai un bouton ASPX qui doit déclencher un script java. I have an ASPX button running a javascript. To do this, I have added in the codebehind :...
by: techfuzz | last post by:
I scoured this group and others looking for the best way to disable a button after the first click to prevent multiple submissions, but never did find anything that worked like they said it would. ...
by: Jeff | last post by:
I need to intercept the Click event of a asp:Button on the client side so that i can disable it after they've clicked it... HOW can i do this?? I was thinking of making the button an HTML button...
by: Elliot M. Rodriguez | last post by:
I have a Delete button in my datagrid. I'm attempting to add some code confirming whether the user wishes to really delete the item or not. The confirm pops up, but I cannot suppress the...
by: IntraRELY | last post by:
I am using the following command to launch and .NET VB Executable, which is a simple Windows Form (printCheckClient.exe). I am using a HyperLink Control and works perfect....
by: Bruce | last post by:
I use btnSave.Attributes.Add("onclick", "ShowMessage()") to link my web control button to a JavaScript function. It works well until I added a Validation control into the page. After that,...
by: bay_dar | last post by:
Hi, I have an internal ASP.NET application that I'm are using to send e-mails out based on a single milepost or milepost range entered. I'm trying to do two things when a user clicks on the...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.