473,473 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
System.Web.UI.WebControls.Button
Protected WithEvents TextBox1 As
System.Web.UI.WebControls.TextBox
Protected WithEvents RequiredFieldValidator1 As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents Label1 As
System.Web.UI.WebControls.Label

#Region " Web Form Designer Generated Code "

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

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.
InitializeComponent()
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"
Codebehind="WebForm1.aspx.vb"
Inherits="AspxTest2.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual
Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic
7.0">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
function ShowMessage()
{
alert("test message");
}
</script>
</HEAD>
<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>
<asp:RequiredFieldValidator
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>
</form>
</body>
</HTML>

Nov 20 '05 #1
1 3856
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 ';'.

Regards,
Fergus
Nov 20 '05 #2

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

Similar topics

4
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. ...
1
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...
2
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 :...
2
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. ...
3
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...
4
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...
7
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....
0
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,...
2
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.