Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to control the SuppresPostBack from a button?

Posted on 2010-01-12
Medium Priority
Last Modified: 2012-05-08
I have a button called getQuote, this button is connected directly to my CollapsiblePanelExtender.
So far this part works great but now I need to add a another functionality;  "getQuote" needs to execute a function in the server side.
Obviously this is not going to work because for the CollapsiblePanelExtender to works I need to add SuppressPostback = true.

How can I make my button do both task at the same time, do the collapsiblePanelExtender and  execute the function from the server side?

I am using C#

ps: please feel free to bring another ideas, I am sore it of new in this world of coding..
<asp:UpdatePanel runat="server" ID="up1">
                    <div class="scrolltotal">
                       <ajaxToolkit:CollapsiblePanelExtender runat="server" 

                       <asp:Panel id="ContentPanel" runat="server" CssClass="collapsePanel">
                         <div class="textInsideScroll" style="padding-left:90px; font-size:11px; font-family:Arial; ">
                            <div class="Contextscroll" style=" padding-left:35px;">
                                <asp:RadioButtonList RepeatDirection="Horizontal" 
                                               id="RadioButtonList1" runat="server"
                                    <asp:ListItem Value="current">50% ($337 / wk)</asp:ListItem>
                                    <asp:ListItem Value="pending">60% ($404 / wk)</asp:ListItem>
                                    <asp:ListItem Value="pending">66% ($449 / wk)</asp:ListItem>
                    <div class="footer">
                             <asp:ImageButton runat="server" ID="getQuote" ImageUrl="images/GetAquote.png" 

        protected void getQuote_Click(object sender, ImageClickEventArgs e)

            img1.ImageUrl = "images/IconPicture.png";

        public void ChangeBlue()
            GLTD.Attributes.Add("class", "container");
            GLTDTop.Attributes.Add("class", "top");
            NoThanks1.Visible = true;
            getQuote.ImageUrl = "images/GetAquote.png";
            Learn.ImageUrl = "images/LearnmoreIcon.png";

Open in new window

Question by:eddyperu
  • 3
  • 2

Expert Comment

ID: 26296266
Although it may seem overwhelming at first glance jQuery is a very simple solution to this problem. jQuery makes calling server-side methods in Asp.Net, Asp.Net MVC, etc. fairly easy.

Take a look at...
to get started and let me know if you need further assistance.

Dave Jellison

Author Comment

ID: 26296333
That looks like fun but I work with my team and I don't think they will go for it :(
Thank either way, Do you have another solution?

Expert Comment

ID: 26296549
I'm looking at your code and I'm unsure if you're doing any server-side specific code in your getQuote_Click & ChangeBlue methods as I don't see where GLTD & GLTDTop are defined but I'm assuming they're asp.net server controls (names/ids)?

What you're trying to accomplish in your methods screams "JavaScript only" needed here to me. When you DO need to call an ajax(ified) server-side method is when you need to query the SQL database, or check the value of a business object, etc. If you're just doing styling I'm unsure of why you (or your team) wants to use an ajax server based call here. It's a bit like using a sledge hammer to open a walnut, it'll work but it's a little bit of overkill. What will happen, even at best optimization is a round-trip to the server posting back some returned HTML (in an UpdatePanel, etc.)

I'm not trying to be the code-police but Ajax IS JavaScript so you're using JS whether you're interacting with it directly or not (as well as the entirety of Asp.Net as well, whether you're using Ajax or not).

So could you please explain, is it just jQuery you and your team wouldn't want to use or customized JavaScript directly or just that you feel the overhead of more JS libraries is a hazard, etc.? That would just give me a better feel for what you're trying to accomplish, how and why if that makes sense...

Author Comment

ID: 26297879
Hi, Thanks
Well...it has to do with policies and all that stuff that this company have, beside this is just a prototype so I am not too worry about how is done . It just need to be done :) May be later on I will be able to do with only javascript.

I just try it in Firefox and it works great. The only problem  that I have found is that with Firefox the visual effect of how the collapsiblePabnel shows is gone, this is using  SuppressPostBack="false" .
If I change it to SuppressPostBack="true", the visual effect works but I run into the same problem where the button code behind is not triggering.

How can I fix this?? any ideas

ps: You are right about the function(getQuote_Click & ChangeBlue ) , the only that it does is changing some style .

Accepted Solution

DaveJellison earned 2000 total points
ID: 26298590
Then only way I could (or would) do it is by adding a quick javascript function to the OnClientClick event of your getQuote ImageButton. You can obfuscate the JavaScript if need be by adding the JS snippet in the page code behind using the ScriptManager.RegisterClientScriptBlock and wiring it to your control & OnClientClick event since it seems AJAX is taking over the OnClick method when you supress postback. The only other "more managed" approach would be to extend the functionality of the AJAX CollapsiblePanel control itself to allow a OnClientClick to be supplied. At the end of the day you'll be using JavaScript no matter what even if the JavaScript is used just to call your Server-Side method. Since your server side method is only making style changes it makes the most sense (to me) to just avoid the "server" side call and just manipulate the styling via JS. I'm still unsure of the reluctance (of your client) to use custom JavaScript. At the end of the day Asp.Net itself and certainly AJAX are just doing "proven" JavaScript calls.

Please Note: I'm not a huge fan of JavaScript because I prefer a much more managed type-safe code language but sometimes you "have to go there". Maybe another expert knows of a way to trick the AJAX control into double-duty on your button control but since the control only allows you to set the Collapse/Expand control Ids and not the methods/functions themselves I don't see a simple way to do it via the Toolkit control. Obviously another button would solve all your problems but I see you're basically trying to get the collapse/expand functionality to work while at the same time calling an additional method so that your styling happens as the panel expands, correct?

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

572 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