473,786 Members | 2,375 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.WriteAtt ribute("OnClick ", "javascript:che ckData();" &
Page.GetPostBac kEventReference (Me, "Data"))

for an Input item so I get something like

<input type="button" value="Submit"
OnClick="javasc ript:checkData( );__doPostBack( 'MyControl','Da ta')" />

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.i tem2.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 1735
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('M yControl','Data ');
}
else
{
alert("Error");
window.event.ca ncelBubble = true;
window.event.re turnValue = 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******* *******@TK2MSFT NGP11.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('M yControl','Data ');
}
else
{
alert("Error");
window.event.ca ncelBubble = true;
window.event.re turnValue = 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
ControlToValida te must be associated with the ID of a control in the same
"naming container". If your custom control impliments INamingContaine r,
ControlToValida te 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****@PeterBlu m.com
Creator of "Profession al Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Samuel Hon" <no*****@samuel hon.co.uk> wrote in message
news:c8******** *************** **@posting.goog le.com...
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.WriteAtt ribute("OnClick ", "javascript:che ckData();" &
Page.GetPostBac kEventReference (Me, "Data"))

for an Input item so I get something like

<input type="button" value="Submit"
OnClick="javasc ript:checkData( );__doPostBack( 'MyControl','Da ta')" />

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.i tem2.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.in fo> wrote in message news:<OC******* ******@TK2MSFTN GP10.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
ControlToValida te must be associated with the ID of a control in the same
"naming container". If your custom control impliments INamingContaine r,
ControlToValida te 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****@PeterBlu m.com
Creator of "Profession al 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
5333
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
1131
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 or utilizing an ArrayList to hold references to the forms, adding a form item to the array each time a new form is loaded, and then looping thru the class of forms to find the reference? 'clsForm is a class similar to an ArrayList
11
3033
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. It works perfectly (assigning the correct images and the correct onclick events to the correct <atags):
4
3882
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 list controls, one text box, one "GO" button, one "reset" button. When the "GO" button is clicked the form gets submitted and the results page is displayed. When I press the "enter" key nothing happens. I want to submit the form by pressing the "enter"...
3
15926
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 are the 2 i need to work for one check box: "toggle(Monday1,true,Sunday1,true)" "addUp(99, 'Monday1')" thanks for your help
1
2680
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 get created event and multiple changed events. After the file is copied (fully) i want to read the file and perform some operations on it. Now the issue is, there is no way to find that the file has been copied entirely.
6
4690
by: Michael Landberg | last post by:
Hi is it possible to load multiple onload events in the body tag? Regards
5
7655
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 click again on that same button than it will open same form again in seperate window. But instead of that already open form comes.and so i couldn't open that form multiple times. Already open form must be remain as it is even if I click on that button...
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9492
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10108
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9960
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7510
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.