Elvio Lujan
asked on
cancel postback in a imagebutton control
Hi
How i can cancel the PostBack in one ImageButton Click Event?
How i can cancel the PostBack in one ImageButton Click Event?
Adding on..
If you need to use an ImageButton control and want to cancel postback..
Use the "Enabled" property.. it will disable postback.
myImageButton.Enabled = false;
This property is not listed in the Property pages, when you use Visual Studio .NET.. but it is an inherited property of ImageButton control(inherited from Image).. see the MSDN documentation here..
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolsimagebuttonmemberstopic.asp
If you need to use an ImageButton control and want to cancel postback..
Use the "Enabled" property.. it will disable postback.
myImageButton.Enabled = false;
This property is not listed in the Property pages, when you use Visual Studio .NET.. but it is an inherited property of ImageButton control(inherited from Image).. see the MSDN documentation here..
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolsimagebuttonmemberstopic.asp
ASKER
ok. but i need to use the control... if i set the property enabled=false... then i'll can't use the control in the next time
You could enable / disable it conditionally ..
As I asked.. >>Why do you want to do that (disable postback) ?? On what condition do you want it to work and on what condition do you want it to not work?
As I asked.. >>Why do you want to do that (disable postback) ?? On what condition do you want it to work and on what condition do you want it to not work?
well I suppose you could do this..
myImageButton.attributes.a dd("onClic k", "javascript:return false")
myImageButton.attributes.a
rather, best to put a semi-colon at then end of that, or you might run into some javascript errors..
myImageButton.attributes.a dd("onClic k", "javascript:return false;")
myImageButton.attributes.a
ASKER
but the link don't execute
ASKER
i have frames in my site and i need press the imagebutton then send the url link to an other frame
well "execute" in an imagebutton is a postback!, unless you've written some javascript otherwise that you aren't telling us about.
ASKER
ok start again...
I need when the event click succed from a imagebutton... goto an url but in other frame!
I need when the event click succed from a imagebutton... goto an url but in other frame!
ASKER
and i need don't reload the frame where is the imagebutton
Do you need to link to postback? ImageButtons are actually form elements (if you ever look at the source), if you don't need the page to postback then you shouldn't be using them. If you just want to do client-side operations you should just define a regular image "<img src="blah.jpg" /> and add an onClick handler that in client-script will change the src attribute of the <iframe>. Is this what you are after?
ASKER
ok. i'll try it
You can even use HyperLink Control from WebControls.
- Set ImageUrl property of HyperLink to your image.
- Set NavigateUrl and Target URL according to your need
-tushar
- Set ImageUrl property of HyperLink to your image.
- Set NavigateUrl and Target URL according to your need
-tushar
ASKER
ok tusharashah... and how i can change the image when the mouse pointer is over the hyprlink control?
It doesn't sound like you need server-side control (where you currently have your ImageButton) at all. Just plain ol' HTML:
<a href="NewPageUrl.aspx" target="otherFrameName"><i mg src="yourImage.jpg"></a>
If you wanna check the image onmouseover:
<a href="NewPageUrl.aspx" target="otherFrameName"
onmouseover="document.getE lementById ('imgBtn') .src='Mous eOverImage .jpg';"
onmouseout="document.getEl ementById( 'imgBtn'). src='yourI mage.jpg'; "
><img id="imgBtn" src="yourImage.jpg"></a>
<a href="NewPageUrl.aspx" target="otherFrameName"><i
If you wanna check the image onmouseover:
<a href="NewPageUrl.aspx" target="otherFrameName"
onmouseover="document.getE
onmouseout="document.getEl
><img id="imgBtn" src="yourImage.jpg"></a>
I will check out the exact syntact, but for mouseover image rotation you can add an attribute to HyperLink in your page_load event liek following
HyperLink1.attributes.add( "onMouseOv er", "javascript:this.src='NEW URL';")
-tushar
HyperLink1.attributes.add(
-tushar
I didn't read all the above, I just wanted to add something about the answer in case you need it.
If you'd like to conditionally cancel postback for an image button, you can use a javascript confirm dialog:
//in code
myImageButton.Attributes.A dd( "onclick", "return confirm( 'Do you still want to PostBack?' );" );
If you'd like to conditionally cancel postback for an image button, you can use a javascript confirm dialog:
//in code
myImageButton.Attributes.A
ASKER
tushar:
your code don't work:
HyperLink1.attributes.add( "onMouseOv er", "javascript:this.src='NEW URL';")
your code don't work:
HyperLink1.attributes.add(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
tanks tushar
Thanks for the A.
Glad I could help. :)
-tushar
Glad I could help. :)
-tushar
If not then why not use an Image control instead??