Saturday, March 31, 2012
Submitting form with multiple onclick events
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('MyControl','D ata')" /
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
SamHi,
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!
Natty Gur <natty@.dao2com.com> wrote in message news:<uSSwHLhAEHA.3348@.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
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: PLBlum@.PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
"Samuel Hon" <noreply@.samuelhon.co.uk> wrote in message
news:c8672b7d.0403040703.c458604@.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('MyControl','D ata')" />
> 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
"Peter Blum" <PLBlum@.Blum.info> wrote in message news:<OC#ZP$uAEHA.624@.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: PLBlum@.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
Wednesday, March 28, 2012
Subtracting Quantities
Hi,
I have a query about updating quantity values within an website written in asp.net 1.1, vb2003 which references an access database. Basically what I want to do is when the customer confirms their order, I want then the number of items purchased to then be subtracted from the Products table in the database. Thus this ensures the number of each item in stock is kept up to date within the database.
My checkout table contains the intCartitemID (autonumber), Cart ID (random number and date value), quantity ordered and the productID for the item purchased.
The products table contains the ProductID, description, attributes, sale price and quantities in stock.
Now I assume I need to take the quantity of item purchased from the checkout table and then subtract this value from the products table. However, how do I put this idea into practice in terms of the asp.net coding ?
Any online examples of coding would help.
Thanks,
Just pass it in a SQL query
"Update productsTable set quantity = quantity - 1 where productID = " & productID
I agree with the above, except not "quantity = quantity - 1" ... but rather "quantity = quantity - @.howMuchWasOrdered"
Thanks both...
Saturday, March 24, 2012
super simple asp question
I'm tryinh to write a restricted character into a variable and i'm not sure what the replacement is.
Basically I want to put a " inside a variable string.
like:
Body = "And he said: "blah blah blah." "
Any idea how to do that and not have the string break?
i'm going to be writing xml with asp and pulling data from a form and I know xml is really sensitive and an apostraphe over quotations won't cut it.
Thanks.
well i know for c# it is string mystring = "hello world\\". you have to use double the \
EDIT: not sure why i used \ in the example, but for a quote you do it the same way string mystring = "hello \"world\"'; giving you hello "world"
In VB.NET you simply double your quotes like so:
Dim strTest As String = "President Bush said ""No Comment"" in response to my question."
ok i'll try these, thanks for your help :)