Solved

Button Control Question

Posted on 2004-04-20
6
215 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
rkekos,
Use this :
btnAddDomain.Attributes.Add( "onclick", "javascript:return confirm('Yes or no?')" );
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now