Solved

Button Control Question

Posted on 2004-04-20
6
217 Views
Last Modified: 2010-04-15
In my application I sometimes have the scenario as follows:

A page performs a certain function like adding a domain name to list.  Sometimes I was to restrict the ability to add more then the allowed amount.  I can create the logic to determine if they can or not in the Page_Load function.  When I do determine that the user should not be able to add more domains I then, within the Page_Load function, do the following to the control:

btnAddDomain.Attributes.Add( "onclick", "alert('You cannot do this action');" );

My question is this causes a postback event which I'd rather not since it's javascript.  I just wish them to see the error and that's it and not have it create a postback.  Yes I could just remove or disable the button or display a message but is there a way to get around this or should I just leave the functionality out since it wouldn't work anyway.
0
Comment
Question by:rkekos
  • 2
6 Comments
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 10871777
rkekos,
try to set false in cancelbubble event. This will help you to stop postback to server:
btnAddDomain.Attributes.Add( "onclick", "javascript:alert('You cannot do this action');
event.cancelBubble =true;event.returnValue = false;" );
0
 
LVL 20

Accepted Solution

by:
TheAvenger earned 125 total points
ID: 10875704
I am not sure, but maybe as a simpler option from what x_com offered, you can use:

btnAddDomain.Attributes.Add( "onclick", "alert('You cannot do this action');return false" );
0
 

Author Comment

by:rkekos
ID: 11071990
What about if you have a Confirm('Yes or No') dialog?  I only want the form to submit if Yes is selected, if No then just cancel without a PostBack.
0
 
LVL 29

Assisted Solution

by:David H.H.Lee
David H.H.Lee earned 125 total points
ID: 11072229
rkekos,
Use this :
btnAddDomain.Attributes.Add( "onclick", "javascript:return confirm('Yes or no?')" );
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question