How do i keep WebForm_DoPostBackWithOptions from rendering to page for Imagebutton?

  • Thread starter Thread starter TS
  • Start date Start date
T

TS

I think it is happening becuase i am setting OnClientClick to be a JS method
to run. I just want the JS code to run and no postback.

I know i can just return false from the custom JS method and it will cancel
the call and wont do the postback, but i dont want all that extra text to be
rendered to the client.

thanks
TS
 
Hi TS,

| I know i can just return false from the custom JS method and it will
cancel
| the call and wont do the postback, but i dont want all that extra text to
be
| rendered to the client.

Please let me know what the extra text you meant. If any ImageButton is
added an onclientclick method, the rendered HTML element like this:
<asp:ImageButton ID="ImageButton1" runat="server"
OnClientClick="clientclick();return false;" />
-->
<input type="image" name="ImageButton1" id="ImageButton1" src=""
onclick="clientclick();return false;" style="border-width:0px;" />

There is no extra text which is rendered. Please post more detailed
description and your repro here.

--
Sincerely,

Zhi-Qiang Ni

Microsoft Online Support


==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
 
it may not be this property that is adding the extra js call.

I have added my custom JS function using onClientclick
(transferListBoxAddAll). DoPostBackWithOptions is added after this call. How
did it get there?

<input href="#" type="image" name="SelectedClients_AddAll"
id="SelectedClients_AddAll" title="Add All" class="ImageButton"
src="../Images/DblDownArrow.gif" onclick="return
transferListBoxAddAll(SelectedClients', SelectedClientsUNSELECTED',
'SelectedClientsSELECTED');WebForm_DoPostBackWithOptions(new
WebForm_PostBackOptions(&quot;SelectedClients_AddAll&quot;, &quot;&quot;,
true, &quot;&quot;, &quot;&quot;, false, false))" style="border-width:0px;"
/>
 
Hi TS,

Sorry for my delay. From your description, I know that you would like to
stop the post back of the imageButton, but although you added 'return
false' in the onclientclick event handler, a 'WebForm_DoPostBackWithOptions
function' is also added into the rendered control and the imageButton still
make post back. If I misunderstood you, please tell me.

The cause of the 'extra' code -- WebForm_DoPostBackWithOptions-is the
imageButton has been added a property 'PostBackURL'. If we set this
property of some button, when we click this button, the page would be post
back to the URL which you set as the value. Such function
'WebForm_DoPostBackWithOptions' is to DoPostBack with the options: the
button's ID and the URL value.

Please remove the setting of the PostBackUrl property to avoid the 'extra'
code.

You said that you added 'return false' inside the client function. However,
in the rendered control, the WebForm_DoPostBackWithOptions function can
still be fired. To avoid this, we can add the 'return false' after the
client function like this:
<asp:ImageButton ID="ImageButton1" runat="server"
Imageurl="~/click.gif" OnClientClick="clientClick();return false;"
PostBackUrl="~/Default.aspx" />

The related document:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.pos
tbackurl.aspx


--
Sincerely,

Zhi-Qiang Ni

Microsoft Online Support


==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
 
postbackUrl is empty string - checked at time of rendering the control.

I had already looked into this as a possible reason but its not the case.
 
Hi TS,

I have tried any property that still cannot reproduce your generate code.
Would you please post the ASP source code of the imageButton and any other
related information here?

--
Sincerely,

Zhi-Qiang Ni

Microsoft Online Support


==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
 
hello, I don't see that you replied to my previous post sent on 02/22:

postbackUrl is empty string - checked at time of rendering the control.

I had already looked into this as a possible reason but its not the case.

thanks
 
thanks zhi-qiang, but I am still having problems...the postbackURL is blank
all the way thru page execution life cycle. It is never set and it is always
blank.

What else could cause this?

thanks
 
from the URL you sent me, it says the following which indicates that even if
you don't enter PostBackUrl it will use current page:

"Set the PostBackUrl property to the URL of the Web page to post to when the
Button control is clicked. For example, specifying Page2.aspx causes the
page that contains the Button control to post to Page2.aspx. If you do not
specify a value for the PostBackUrl property, the page posts back to
itself."

so it is using the current page whether specified or not.

please help
 
Back
Top