G
Guest
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">
<asplaceholder id="phLeftNav" Runat="server"></asplaceholder></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=13640&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
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">
<asplaceholder id="phLeftNav" Runat="server"></asplaceholder></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=13640&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