Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Button Control Question

Posted on 2004-04-20
6
Medium Priority
?
222 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 375 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 375 total points
ID: 11072229
rkekos,
Use this :
btnAddDomain.Attributes.Add( "onclick", "javascript:return confirm('Yes or no?')" );
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .

963 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