Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Button Control Question

Posted on 2004-04-20
6
Medium Priority
?
220 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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

670 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