?
Solved

How to control the SuppresPostBack from a button?

Posted on 2010-01-12
5
Medium Priority
?
258 Views
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#

Thanks
ps: please feel free to bring another ideas, I am sore it of new in this world of coding..
>Thanks
<asp:UpdatePanel runat="server" ID="up1">
             <ContentTemplate>
                    <div class="scrolltotal">
                       <ajaxToolkit:CollapsiblePanelExtender runat="server" 
                              TargetControlID="ContentPanel"
                              ExpandControlID="getQuote"
                              CollapseControlID="getQuote"
                              Collapsed="true" 
                              SuppressPostBack="true">
                       </ajaxToolkit:CollapsiblePanelExtender>

                       <asp:Panel id="ContentPanel" runat="server" CssClass="collapsePanel">
                         <div class="textInsideScroll" style="padding-left:90px; font-size:11px; font-family:Arial; ">
                           <div>
                                percent 
                           </div>
                            <div class="Contextscroll" style=" padding-left:35px;">
                                <asp:RadioButtonList RepeatDirection="Horizontal" 
                                               id="RadioButtonList1" runat="server"
                                             Width="460px">
                                    <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>
                                </asp:RadioButtonList>                       
                            </div>
                         </div>
                       </asp:Panel>
                    </div>
                    <div class="footer">
                             <asp:ImageButton runat="server" ID="getQuote" ImageUrl="images/GetAquote.png" 
                                      onclick="getQuote_Click"/>
                    </div>
             </ContentTemplate>
           </asp:UpdatePanel>  

CodeBehind:
        protected void getQuote_Click(object sender, ImageClickEventArgs e)
        {

            ChangeBlue();
            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

0
Comment
Question by:eddyperu
[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
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:DaveJellison
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...
http://www.dexign.net/post/2008/07/16/jQuery-To-Call-ASPNET-Page-Methods-and-Web-Services.aspx
to get started and let me know if you need further assistance.

Dave Jellison
0
 
LVL 4

Author Comment

by:eddyperu
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?
Thanks
0
 
LVL 4

Expert Comment

by:DaveJellison
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...
0
 
LVL 4

Author Comment

by:eddyperu
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
Thanks

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

Accepted Solution

by:
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?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This article discusses how to implement server side field validation and display customized error messages to the client.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

777 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