Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4558454
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:39:08+00:00 2026-05-21T17:39:08+00:00

I would like to first load an ASP.NET page and then fire a server-side

  • 0

I would like to first load an ASP.NET page and then fire a server-side event that in turn updates some html on the client. The event is tied to an Anthem.NET imagebutton control, so the logical course of action would be to just fire the event of that control. However, if there is another approach to firing this server-side event and returning the resulting html of a usercontrol to the client I will also consider it. I am using ASP.NET 3.5, the Anthem.NET framework, and JQuery 1.4.4.

I have been working on this for several hours and have gone through several posts that appeared to have an answer, however none seemed to do the trick – at least not that will work in every browser.

The button I am trying to fire:

<anthem:ImageButton runat="server" ID="btnGetRates" 
    ImageUrl="~/BVModules/Themes/BVC5/Images/Buttons/GetRates.png"
    TextDuringCallBack="Retrieving rates...">
</anthem:ImageButton>

Which looks like this when rendered on the client:

<span id="Anthem_ctl00_MainContentHolder_EstimateShippingDisplay2_btnGetRates__">
    <input type="image" 
        name="ctl00$MainContentHolder$EstimateShippingDisplay2$btnGetRates"
        id="ctl00_MainContentHolder_EstimateShippingDisplay2_btnGetRates"
        src="BVModules/Themes/Depot/images/buttons/GetRates.gif"
        onclick="javascript:Anthem_FireCallBackEvent(this,event,'ctl00$MainContentHolder$EstimateShippingDisplay2$btnGetRates','',true,'','','Retrieving rates...',true,null,initAccordion,null,true,true);return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$MainContentHolder$EstimateShippingDisplay2$btnGetRates&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" 
        style="border-width:0px;" />
</span>

Approach 1:

jQuery(document).ready(function() {
  setTimeout(getRates, 5000);
});

function getRates() {
  jQuery('#ctl00_MainContentHolder_EstimateShippingDisplay2_btnGetRates').click();
}

Using this method makes the button text update to "Retrieving Rates…", however the call never makes it to the server and it just hangs indefinitely (in IE7). In Firefox, the button changes for a split second and then changes back, and the call to the server is also not fired.

Interestingly, if the getRates() function is called from a button click event instead of from (document).ready() it will function (in IE, but not Firefox).

Approach 2:

I followed the instructions in the accepted answer in Call ASP.NET function from JavaScript?, but in addition to not causing my server side method to fire, this approach didn’t address the fact that I want the output html of a user control to appear on the client when the method is complete.

Approach 3:

jQuery(document).ready(function() {
  setTimeout(getRates, 5000);
});

function getRates() {
  var btn = document.getElementById('ctl00_MainContentHolder_EstimateShippingDisplay2_btnGetRates');
  fireEvent(btn,'click');
}

function fireEvent(element,event){
  if (document.createEventObject){
    var evt = document.createEventObject();
    return element.fireEvent('on'+event,evt)
  } else {
    var evt = document.createEvent("HTMLEvents");
    evt.initEvent(event, true, true ); // event type,bubbling,cancelable
    return !element.dispatchEvent(evt);
  }
}

I found this method of firing the events here.

Rather than using a jQuery approach, this goes back to the basics of JavaScript. This method works perfectly in IE, but once again I am having issues with Firefox. Since this is working in one browser, I know I must be getting close.

Interestingly, even though this went from sort-of working to completely working in IE, the behavior of Firefox is exactly the same as it was with Approach #1 – the button changes for an instant to the text "Retrieving Rates…" and changes back so fast it is just barely noticeable.

Another Clue:

I dug into the Anthem.NET JavaScript to see if I could find a clue as to what is happening. Although I found a clue, I am not sure exactly why it is causing this difference in browser behavior, or more specifically what the code to handle this different behavior looks like. As you can see by the following code, the button event is being attached differently for IE than for other browsers. And in case you are wondering, yes I am using validation controls (validators).

// Primarily used by Anthem.Manager to add an onsubmit event handler
// when validators are added to a page during a callback.
function Anthem_AddEvent(control, eventType, functionPrefix) {
    var ev;
    eval("ev = control." + eventType + ";");
    if (typeof(ev) == "function") {
        ev = ev.toString();
        ev = ev.substring(ev.indexOf("{") + 1, ev.lastIndexOf("}"));
    }
    else {
        ev = "";
    }
    var func;
    if (navigator.appName.toLowerCase().indexOf('explorer') > -1) {
        func = new Function(functionPrefix + " " + ev);
    }
    else {
        func = new Function("event", functionPrefix + " " + ev);
    }
    eval("control." + eventType + " = func;");
}

I am almost ready to throw in the towel and start working on an approach that uses a web service to get the output html of my user control and then returning it to jQuery so it can be replaced on the client-side form, but I thought I would check to see if anyone could give me a clue as to how to get approach #3 working in non-IE browsers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:39:09+00:00Added an answer on May 21, 2026 at 5:39 pm

    You already provided the answer you need, it lies in the onclick event of the rendered control.

    onclick="javascript:Anthem_FireCallBackEvent(this,event,'ctl00$MainContentHolder$EstimateShippingDisplay2$btnGetRates','',true,'','','Retrieving rates...',true,null,initAccordion,null,true,true);
    

    You can put the call to Anthem_FireCallBackEvent wherever you like, but you need to tighten it up a bit like this:

    Anthem_FireCallBackEvent(document.getElementById('<%= btnGetRates.ClientID %>'),event,'<%= btnGetRates.UniqueId%>','',true,'','','Retrieving rates...',true,null,initAccordion,null,true,true);
    

    pass it any event you want, but the event can’t be null or you’ll get error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.