473,405 Members | 2,445 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,405 software developers and data experts.

Add client event to user control?

I have a user control as my Save button for my page. When the Save button is
clicked, I want some client-side validation to take place from a javascript
function in the page, and then I'd like the server event to fire to update
the database. I've successfully done this with a normal webcontrol via:
myControl.Attributes("onclick") = "javascript:alert('You clicked me!!');"

In that case, myControl is an asp:button on the page.

In the case where I'm having a problem, I have a link button wrapped in a
user control, and I can set the properties of it in my aspx.vb page. I tried
the same thing, but the user control doesn't ever fire the client event. Can
anyone tell me what I'm missing? Here's a sample of the pieces I have...

When I click the SaveContinue button in the user control, I need the
ValidateForm() function to fire in the javascript code, then the
lbtnSaveContinue_Click event on the server.

THANKS!!!

Aspx form:
function ValidateForm(form) {

alert("Form validated!");

}

…some HTML ...
<td vAlign="top" width="100" bgColor="teal">
<asp:placeholder id="phLeftNav" Runat="server"></asp:placeholder></td>

…more HTML ….

-------------------------------------------------------------
Aspx.vb form:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

left = LoadControl("../LeftNav.ascx")
With CType(left, LeftNav)
'Add a client-side onclick event to the buttons.
'The client-side event will fire first, then the postback.
.SaveContinue.Attributes.Add("onclick", "return
ValidateForm(this);")
End With
phLeftNav.Controls.Add(left)
End Sub

Protected Sub lbtnSaveContinue_Click() Handles left.SaveContinueEvent
Dim SaveMe As New CompanyBC
'I'm expecting the client side code to fire before I get here, but I get
'here first.
SaveMe.SaveForm()

End Sub
-------------------------------------------------------------
leftNav.aspx (user control):

<asp:LinkButton ID="lbtnSaveContinue" Runat="server"
CssClass="LeftButtonOff" AccessKey="o"
CommandArgument="CompanySummary.aspx?companyid=136 40&redirect=true"
ForeColor="White"> Save & C<u>o</u>ntinue</asp:LinkButton>

leftNav.aspx.vb:
Region " Web Form Designer Generated Code "

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

End Sub

Protected WithEvents lbtnSaveContinue As
System.Web.UI.WebControls.LinkButton
Public Event SaveContinueEvent()

… more generated code...

#End Region
Public Property SaveContinueButton() As WebControls.LinkButton
Get
Return lbtnSaveContinue
End Get
Set(ByVal Value As WebControls.LinkButton)
lbtnSaveContinue = Value
End Set
End Property

Private Sub lbtnSaveContinue_click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lbtnSaveContinue.Click
RaiseEvent SaveContinueEvent()
End Sub
Nov 18 '05 #1
4 4464
Look at the output of the page. Is there 2 onclick's wired to the same
button? It will only call one of them.

Checkout link to see what it is your dealing with (perhaps) (this was just
the first link I found, there are many)
http://tinyurl.com/6zyjw

HTH,
Greg

"Barb" <Ba**@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com...
I have a user control as my Save button for my page. When the Save button
is
clicked, I want some client-side validation to take place from a
javascript
function in the page, and then I'd like the server event to fire to update
the database. I've successfully done this with a normal webcontrol via:
myControl.Attributes("onclick") = "javascript:alert('You clicked me!!');"

In that case, myControl is an asp:button on the page.

In the case where I'm having a problem, I have a link button wrapped in a
user control, and I can set the properties of it in my aspx.vb page. I
tried
the same thing, but the user control doesn't ever fire the client event.
Can
anyone tell me what I'm missing? Here's a sample of the pieces I have...

When I click the SaveContinue button in the user control, I need the
ValidateForm() function to fire in the javascript code, then the
lbtnSaveContinue_Click event on the server.

THANKS!!!

Aspx form:
function ValidateForm(form) {

alert("Form validated!");

}

.some HTML ...
<td vAlign="top" width="100" bgColor="teal">
<asp:placeholder id="phLeftNav" Runat="server"></asp:placeholder></td>

.more HTML ..

-------------------------------------------------------------
Aspx.vb form:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

left = LoadControl("../LeftNav.ascx")
With CType(left, LeftNav)
'Add a client-side onclick event to the buttons.
'The client-side event will fire first, then the postback.
.SaveContinue.Attributes.Add("onclick", "return
ValidateForm(this);")
End With
phLeftNav.Controls.Add(left)
End Sub

Protected Sub lbtnSaveContinue_Click() Handles left.SaveContinueEvent
Dim SaveMe As New CompanyBC
'I'm expecting the client side code to fire before I get here, but I get
'here first.
SaveMe.SaveForm()

End Sub
-------------------------------------------------------------
leftNav.aspx (user control):

<asp:LinkButton ID="lbtnSaveContinue" Runat="server"
CssClass="LeftButtonOff" AccessKey="o"
CommandArgument="CompanySummary.aspx?companyid=136 40&redirect=true"
ForeColor="White"> Save & C<u>o</u>ntinue</asp:LinkButton>

leftNav.aspx.vb:
Region " Web Form Designer Generated Code "

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

End Sub

Protected WithEvents lbtnSaveContinue As
System.Web.UI.WebControls.LinkButton
Public Event SaveContinueEvent()

. more generated code...

#End Region
Public Property SaveContinueButton() As WebControls.LinkButton
Get
Return lbtnSaveContinue
End Get
Set(ByVal Value As WebControls.LinkButton)
lbtnSaveContinue = Value
End Set
End Property

Private Sub lbtnSaveContinue_click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles lbtnSaveContinue.Click
RaiseEvent SaveContinueEvent()
End Sub

Nov 18 '05 #2
My problem is seems the opposite...no onClick events in the source of the
page. BUT, it's a link button rather than a button. And there is javascript
call in the <a href> - here's the view source section:

<a id="_ctl8_lbtnSaveContinue" accesskey="o"
href="javascript:__doPostBack('_ctl8$lbtnSaveConti nue','')"
style="color:White;"> Save & C<u>o</u>ntinue</a>

Any ideas? Is the problem that I'm using a link button? I like the link
button because it looks the way I need it to look. Button's didn't seem
versatile enough for me to achieve the look that I need to make this look
right.

"Greg Burns" wrote:
Look at the output of the page. Is there 2 onclick's wired to the same
button? It will only call one of them.

Checkout link to see what it is your dealing with (perhaps) (this was just
the first link I found, there are many)
http://tinyurl.com/6zyjw

HTH,
Greg

"Barb" <Ba**@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com...
I have a user control as my Save button for my page. When the Save button
is
clicked, I want some client-side validation to take place from a
javascript
function in the page, and then I'd like the server event to fire to update
the database. I've successfully done this with a normal webcontrol via:
myControl.Attributes("onclick") = "javascript:alert('You clicked me!!');"

In that case, myControl is an asp:button on the page.

In the case where I'm having a problem, I have a link button wrapped in a
user control, and I can set the properties of it in my aspx.vb page. I
tried
the same thing, but the user control doesn't ever fire the client event.
Can
anyone tell me what I'm missing? Here's a sample of the pieces I have...

When I click the SaveContinue button in the user control, I need the
ValidateForm() function to fire in the javascript code, then the
lbtnSaveContinue_Click event on the server.

THANKS!!!

Aspx form:
function ValidateForm(form) {

alert("Form validated!");

}

.some HTML ...
<td vAlign="top" width="100" bgColor="teal">
<asp:placeholder id="phLeftNav" Runat="server"></asp:placeholder></td>

.more HTML ..

-------------------------------------------------------------
Aspx.vb form:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

left = LoadControl("../LeftNav.ascx")
With CType(left, LeftNav)
'Add a client-side onclick event to the buttons.
'The client-side event will fire first, then the postback.
.SaveContinue.Attributes.Add("onclick", "return
ValidateForm(this);")
End With
phLeftNav.Controls.Add(left)
End Sub

Protected Sub lbtnSaveContinue_Click() Handles left.SaveContinueEvent
Dim SaveMe As New CompanyBC
'I'm expecting the client side code to fire before I get here, but I get
'here first.
SaveMe.SaveForm()

End Sub
-------------------------------------------------------------
leftNav.aspx (user control):

<asp:LinkButton ID="lbtnSaveContinue" Runat="server"
CssClass="LeftButtonOff" AccessKey="o"
CommandArgument="CompanySummary.aspx?companyid=136 40&redirect=true"
ForeColor="White"> Save & C<u>o</u>ntinue</asp:LinkButton>

leftNav.aspx.vb:
Region " Web Form Designer Generated Code "

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

End Sub

Protected WithEvents lbtnSaveContinue As
System.Web.UI.WebControls.LinkButton
Public Event SaveContinueEvent()

. more generated code...

#End Region
Public Property SaveContinueButton() As WebControls.LinkButton
Get
Return lbtnSaveContinue
End Get
Set(ByVal Value As WebControls.LinkButton)
lbtnSaveContinue = Value
End Set
End Property

Private Sub lbtnSaveContinue_click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles lbtnSaveContinue.Click
RaiseEvent SaveContinueEvent()
End Sub


Nov 18 '05 #3
Hi,

You might need to change the control name in the doPostBack function to:

'_ctl8_lbtnSaveContinue'

The $ might be throwing it off but I'm not sure. It is worth a try. Also,
maybe you don't even need to put the _ctl8$ or _ctl8_ in there at all
because the server might not need it. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Barb" <Ba**@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
My problem is seems the opposite...no onClick events in the source of the
page. BUT, it's a link button rather than a button. And there is javascript call in the <a href> - here's the view source section:

<a id="_ctl8_lbtnSaveContinue" accesskey="o"
href="javascript:__doPostBack('_ctl8$lbtnSaveConti nue','')"
style="color:White;"> Save & C<u>o</u>ntinue</a>

Any ideas? Is the problem that I'm using a link button? I like the link
button because it looks the way I need it to look. Button's didn't seem
versatile enough for me to achieve the look that I need to make this look
right.

"Greg Burns" wrote:
Look at the output of the page. Is there 2 onclick's wired to the same
button? It will only call one of them.

Checkout link to see what it is your dealing with (perhaps) (this was just the first link I found, there are many)
http://tinyurl.com/6zyjw

HTH,
Greg

"Barb" <Ba**@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com...
I have a user control as my Save button for my page. When the Save buttonis
clicked, I want some client-side validation to take place from a
javascript
function in the page, and then I'd like the server event to fire to update the database. I've successfully done this with a normal webcontrol via: myControl.Attributes("onclick") = "javascript:alert('You clicked me!!');"
In that case, myControl is an asp:button on the page.

In the case where I'm having a problem, I have a link button wrapped in a user control, and I can set the properties of it in my aspx.vb page. I tried
the same thing, but the user control doesn't ever fire the client event. Can
anyone tell me what I'm missing? Here's a sample of the pieces I have...
When I click the SaveContinue button in the user control, I need the
ValidateForm() function to fire in the javascript code, then the
lbtnSaveContinue_Click event on the server.

THANKS!!!

Aspx form:
function ValidateForm(form) {

alert("Form validated!");

}

.some HTML ...
<td vAlign="top" width="100" bgColor="teal">
<asp:placeholder id="phLeftNav" Runat="server"></asp:placeholder></td>
.more HTML ..

-------------------------------------------------------------
Aspx.vb form:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

left = LoadControl("../LeftNav.ascx")
With CType(left, LeftNav)
'Add a client-side onclick event to the buttons.
'The client-side event will fire first, then the postback.
.SaveContinue.Attributes.Add("onclick", "return
ValidateForm(this);")
End With
phLeftNav.Controls.Add(left)
End Sub

Protected Sub lbtnSaveContinue_Click() Handles left.SaveContinueEvent Dim SaveMe As New CompanyBC
'I'm expecting the client side code to fire before I get here, but I get 'here first.
SaveMe.SaveForm()

End Sub
-------------------------------------------------------------
leftNav.aspx (user control):

<asp:LinkButton ID="lbtnSaveContinue" Runat="server"
CssClass="LeftButtonOff" AccessKey="o"
CommandArgument="CompanySummary.aspx?companyid=136 40&redirect=true"
ForeColor="White"> Save & C<u>o</u>ntinue</asp:LinkButton>

leftNav.aspx.vb:
Region " Web Form Designer Generated Code "

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

End Sub

Protected WithEvents lbtnSaveContinue As
System.Web.UI.WebControls.LinkButton
Public Event SaveContinueEvent()

. more generated code...

#End Region
Public Property SaveContinueButton() As WebControls.LinkButton
Get
Return lbtnSaveContinue
End Get
Set(ByVal Value As WebControls.LinkButton)
lbtnSaveContinue = Value
End Set
End Property

Private Sub lbtnSaveContinue_click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lbtnSaveContinue.Click
RaiseEvent SaveContinueEvent()
End Sub


Nov 18 '05 #4
Ok, I tried changing my linkbutton to a button, and now I can get the
client-side script event to fire.

I couldn't make a button look right for me before, but I'm now finding it
easier to make an asp:button look different than to fire client-side code
from a link button.

Thanks Greg for your help. I think I'm all set on this one.

"Barb" wrote:
I have a user control as my Save button for my page. When the Save button is
clicked, I want some client-side validation to take place from a javascript
function in the page, and then I'd like the server event to fire to update
the database. I've successfully done this with a normal webcontrol via:
myControl.Attributes("onclick") = "javascript:alert('You clicked me!!');"

In that case, myControl is an asp:button on the page.

In the case where I'm having a problem, I have a link button wrapped in a
user control, and I can set the properties of it in my aspx.vb page. I tried
the same thing, but the user control doesn't ever fire the client event. Can
anyone tell me what I'm missing? Here's a sample of the pieces I have...

When I click the SaveContinue button in the user control, I need the
ValidateForm() function to fire in the javascript code, then the
lbtnSaveContinue_Click event on the server.

THANKS!!!

Aspx form:
function ValidateForm(form) {

alert("Form validated!");

}

…some HTML ...
<td vAlign="top" width="100" bgColor="teal">
<asp:placeholder id="phLeftNav" Runat="server"></asp:placeholder></td>

…more HTML ….

-------------------------------------------------------------
Aspx.vb form:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

left = LoadControl("../LeftNav.ascx")
With CType(left, LeftNav)
'Add a client-side onclick event to the buttons.
'The client-side event will fire first, then the postback.
.SaveContinue.Attributes.Add("onclick", "return
ValidateForm(this);")
End With
phLeftNav.Controls.Add(left)
End Sub

Protected Sub lbtnSaveContinue_Click() Handles left.SaveContinueEvent
Dim SaveMe As New CompanyBC
'I'm expecting the client side code to fire before I get here, but I get
'here first.
SaveMe.SaveForm()

End Sub
-------------------------------------------------------------
leftNav.aspx (user control):

<asp:LinkButton ID="lbtnSaveContinue" Runat="server"
CssClass="LeftButtonOff" AccessKey="o"
CommandArgument="CompanySummary.aspx?companyid=136 40&redirect=true"
ForeColor="White"> Save & C<u>o</u>ntinue</asp:LinkButton>

leftNav.aspx.vb:
Region " Web Form Designer Generated Code "

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

End Sub

Protected WithEvents lbtnSaveContinue As
System.Web.UI.WebControls.LinkButton
Public Event SaveContinueEvent()

… more generated code...

#End Region
Public Property SaveContinueButton() As WebControls.LinkButton
Get
Return lbtnSaveContinue
End Get
Set(ByVal Value As WebControls.LinkButton)
lbtnSaveContinue = Value
End Set
End Property

Private Sub lbtnSaveContinue_click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lbtnSaveContinue.Click
RaiseEvent SaveContinueEvent()
End Sub

Nov 18 '05 #5

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

Similar topics

4
by: Gaz | last post by:
This is impossible right?? This is a very simplified description of my form so don't worry if it sounds like I could do it a different way, it's just because I have simplified it. I have two...
1
by: Jim Hammond | last post by:
I can get data from a client-side assembly to the server in two manual steps, but I need to be able to do it in one step. Step 1: The user presses the manually coded "Step 1" button, which calls...
17
by: Zvi Danovich | last post by:
Hi, I am a newby in ASP.NET, and till now wrote only simple "classic" WEB-sites. But - the time came, and now I need that: 1. Server will "listen" for some events on its local machine 2....
3
by: Larry David | last post by:
Hi, I'm just trying to wrap my mind around the ASP.NET model. Let me walk you through a trivial scenario: Let's say I have a form containing a text box where the user enters his name. It also...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
3
by: sklett | last post by:
I need to add extensive validation and interaction client scripting to a web form. I've done some initial searches for "asp.net and client scripting" and I've found a couple articles that show...
3
by: CodeRazor | last post by:
I have a user contol hosted in a webform. The user control interfaces with an http component. When the user control loads, a request is sent to the http component. It takes around 10 seconds...
1
by: John Dalberg | last post by:
What causes a server event to fire when something happens on the client? Say a user changed the gridview's page index, the server side PageIndexChanged event is fires. What makes...
0
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, imagine this for a moment if you will: i have a row in a gridview that when it is in edit mode there is a column that contains a dropdownlist and 2nd column that contains a user control....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
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...

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.