Solved

Button Control Question

Posted on 2004-04-20
6
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

622 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