473,508 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Submitting form with multiple onclick events

Hi

I'm building a custom control which basically takes data from the user
and then submits it. I would use the validator controls but if I
understand correctly (I've been working with .Net for 2 weeks) you
cant 'embed' them in the custom controls. Someone correct me if I'm
wrong (and please point to an example :) )

So, to get around this, I'm using Javascript. In my control, I'm doing

Writer.WriteAttribute("OnClick", "javascript:checkData();" &
Page.GetPostBackEventReference(Me, "Data"))

for an Input item so I get something like

<input type="button" value="Submit"
OnClick="javascript:checkData();__doPostBack('MyCo ntrol','Data')" />

The checkData() function does this:

function checkLogin()
{
if (document.Data.item1.value == "" )
{
alert("Please enter item 1.");
return false;
}

if (document.Data.item2.value == "" )
{
alert("Please enter item 2.");
return false;
}

if (document.Data.item1.value != "" && document.Data.item2.value !=
"" )
{
return true;
}

}

My query is, how do I get the click event to fire correctly so that i
get alerts when there is a problem, and it passes through and submits
the form if there isnt a problem?

Thanks

Sam
Nov 18 '05 #1
4 1724
Hi,

Your client side script should use cancelBubble and returnValue to
disable event default process and raise alert if error found.

function CallServer()
{
if validate
{
__doPostBack('MyControl','Data');
}
else
{
alert("Error");
window.event.cancelBubble = true;
window.event.returnValue = false;
}
}
HTH

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2
Natty Gur <na***@dao2com.com> wrote in message news:<uS**************@TK2MSFTNGP11.phx.gbl>...
Hi,

Your client side script should use cancelBubble and returnValue to
disable event default process and raise alert if error found.

function CallServer()
{
if validate
{
__doPostBack('MyControl','Data');
}
else
{
alert("Error");
window.event.cancelBubble = true;
window.event.returnValue = false;
}
}
HTH

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Thanks Natty

This means I have to create inline javascripts which I'd rather not do
if I can help it. Just as luck would have it, after spending an 'hour
or two' trying to find a solution before posting, 5 mins after posting
I find a solution :( Always the way...

Anyhow, just for reference purposes, what I've done is to validate on
OnMouseDown and postback on OnClick. Works a treat
Nov 18 '05 #3
Hi Samuel,

Its unfortunate that you had to rework validation because of some incorrect
information about validators. The ASP.NET validators work fine within custom
controls. They have one key limitation related to their "location": the
ControlToValidate must be associated with the ID of a control in the same
"naming container". If your custom control impliments INamingContainer,
ControlToValidate can only point to other controls within your custom
control. If not, it can refer to other controls in the same naming container
that your custom control appears. Some types of naming containers: Page,
UserControl, and rows in DataGrid and DataList.

If you wanted to support validation without naming container limits, I wrote
a replacement to Microsoft's validators that overcomes that limitation among
numerous others: Professional Validation And More.
http://www.peterblum.com/vam/home.aspx.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Samuel Hon" <no*****@samuelhon.co.uk> wrote in message
news:c8*************************@posting.google.co m...
Hi

I'm building a custom control which basically takes data from the user
and then submits it. I would use the validator controls but if I
understand correctly (I've been working with .Net for 2 weeks) you
cant 'embed' them in the custom controls. Someone correct me if I'm
wrong (and please point to an example :) )

So, to get around this, I'm using Javascript. In my control, I'm doing

Writer.WriteAttribute("OnClick", "javascript:checkData();" &
Page.GetPostBackEventReference(Me, "Data"))

for an Input item so I get something like

<input type="button" value="Submit"
OnClick="javascript:checkData();__doPostBack('MyCo ntrol','Data')" />

The checkData() function does this:

function checkLogin()
{
if (document.Data.item1.value == "" )
{
alert("Please enter item 1.");
return false;
}

if (document.Data.item2.value == "" )
{
alert("Please enter item 2.");
return false;
}

if (document.Data.item1.value != "" && document.Data.item2.value !=
"" )
{
return true;
}

}

My query is, how do I get the click event to fire correctly so that i
get alerts when there is a problem, and it passes through and submits
the form if there isnt a problem?

Thanks

Sam

Nov 18 '05 #4
"Peter Blum" <PL****@Blum.info> wrote in message news:<OC*************@TK2MSFTNGP10.phx.gbl>...
Hi Samuel,

Its unfortunate that you had to rework validation because of some incorrect
information about validators. The ASP.NET validators work fine within custom
controls. They have one key limitation related to their "location": the
ControlToValidate must be associated with the ID of a control in the same
"naming container". If your custom control impliments INamingContainer,
ControlToValidate can only point to other controls within your custom
control. If not, it can refer to other controls in the same naming container
that your custom control appears. Some types of naming containers: Page,
UserControl, and rows in DataGrid and DataList.

If you wanted to support validation without naming container limits, I wrote
a replacement to Microsoft's validators that overcomes that limitation among
numerous others: Professional Validation And More.
http://www.peterblum.com/vam/home.aspx.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

<snip>

Thanks Peter for clearing that up, I will re-investigate

Sam
Nov 18 '05 #5

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

Similar topics

6
5313
by: Tom | last post by:
Hi, In the following code I have reproduced a problem in IE that is extremely annoying for my application. <html> <head> <script type="text/javascript">
2
1122
by: Dean Slindee | last post by:
I have two different independent forms that need to talk to one another to syncronize their displays. Is there a shorter way of referring to another form's controls/events than creating a class...
11
2975
by: GaryB | last post by:
Hi Guys, I've been battling with this one for hours - I hope that you can help me! My code modifies the <aon a page, from a standard document link into a link with a tailored onclick event. ...
4
3859
by: roxanaislam | last post by:
Submitting Form by pressing the "ENTER" key -------------------------------------------------------------------------------- Hi: I have a search form in my application which has 4 dropdown...
3
15908
by: macsaregreat | last post by:
How do you apply 2 onclick events to a check box. I googled this and found multiple ways of doing it, but they dont work. Maybe i was not using the correct syntax, but i cant figure it out. these...
1
2641
by: D2 | last post by:
Hi, I have this problem when working with FileSystemWatcher class. I m using one of these objects to watch over a folder. Whenever i big file from another folder to the folder being watched, I...
6
4679
by: Michael Landberg | last post by:
Hi is it possible to load multiple onload events in the body tag? Regards
5
7614
by: billa856 | last post by:
Hi, My project is in MS Access 2002. In that I want to open one form multiple times. I put one button on my main form. Now whenever I click on that button than form will be open. Now when I...
0
7226
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
7125
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
7388
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
7499
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
5631
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
5055
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
3199
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
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.