PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

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

 
 
Bruce
Guest
Posts: n/a
 
      16th Oct 2003
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 has 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>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data validation doesn't work if contents is added by pasting jeff.taylor@virgin.net Microsoft Excel Discussion 1 5th Nov 2006 09:25 PM
Re: button attributes disable validation Tim Meagher Microsoft C# .NET 0 31st Aug 2005 07:57 PM
how come user control added to page doesn't get added to codebehind file? Bennett Haselton Microsoft ASP .NET 1 8th Nov 2004 09:26 PM
Button Doesn't Work on Panel with Validation Control Spence Hackney Microsoft ASP .NET 4 19th Jul 2004 08:22 PM
button.Attributes.Add does not work after I added Validation control on the page Bruce Microsoft VB .NET 1 15th Oct 2003 10:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:31 PM.