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

  • SEARCH
  • Home
  • 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 6973937
In Process

The Archive Base Latest Questions

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

I have a custom control (ascx) which implements the IPostBackEventHandler interface for intercepting custom

  • 0

I have a custom control (ascx) which implements the IPostBackEventHandler interface for intercepting custom events triggered by custom rendered HTML links.

In this control I use an update panel and inside the update panel I use a literal control in which I render custom HTML links.

When I render the HTML links inside the literal control I use a StringBuilder with the following code:

sb.AppendFormat ("<a href=\"{0}\" id=\"custom_iterator_id\">Text</a>",
    this.Page.ClientScript.GetPostBackClientHyperlink(this, custom_string_param));

Hyperlinks are rendered fine, and when clicking on them an asynchronous postback is triggered and a partial update is fired (since all links are rendered inside the Update panel).

The problem is that I need to do some custom Javascript before firing the __doPostBack which is rendered with the above code. So here is a simplified version of the changed code:

sb.AppendFormat ("<a href=\"javascript:JSFunc{0}\" id=\"custom_iterator_id\">Text</a>",
    custom_string_param);

Also in the ascx markup I use the following code (inside or outside the Update panel):

<script language="javascript" type="text/javascript">
function JSFunc(param) {
// custom js code here .... 
__doPostBack('<%=this.ClientID%>', param);
}
</script>

The problem here is that when a link is clicked it performs a full postback and not a partial one. I also tested more simple versions of the above code and it seems that if you remove the __doPostBack from the href or the onclick events from the link ( tag) and move it to a custom js function which in turns you supply to the link, a full postback is triggered.

Note that there is no error on the page and in both cases the code work correctly. The page is rendering correctly depending on the parameters returned from the __doPostBack, but in the second case a full instead of partial postback is firing.

Any ideas?

Thanks in advance,

George

  • 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-27T17:10:21+00:00Added an answer on May 27, 2026 at 5:10 pm

    I think you can’t call __doPostBack with the ClientID. It actually uses UniqueIDWithDollars, but generally with ASP.NET Web Forms I say: you don’t want to know.

    Since calling this method is all about abstracting away the details of how post back works, you would be better off asking the framework for the code. Luckily, there’s a special method just for that, which will take care of the details. In your code it would look like something like this:

    <script language="javascript" type="text/javascript">
        function JSFunc(param) {
            // custom js code here .... 
            <%= Page.ClientScript.GetPostBackEventReference(this, custom_string_param) %>
        }
    </script>
    

    This let’s the client script manager create the piece of JavaScript code, using a reference to your user control (this) and any custom event argument (custom_string_param).

    There’s one caveat though. When calling it this way, it will add javascript: to the beginning of the string.

    To override this behaviour, you need to use an overload of GetPostBackEventReference that accepts an instance of PostBackOptions as its first argument, the instance having its RequiresJavaScriptProtocol property set to false.

    PostBackOptions options = new PostBackOptions(this, custom_string_param)
    options.RequiresJavaScriptProtocol = false;
    Page.ClientScript.GetPostBackEventReference(options)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom control that implements IPostBackEventHandler. Some client-side events invoke __doPostBack(controlID, eventArgs).
If I have a custom user control (say, MyCustomControl.ascx) which contains a number of
I have a custom control that inherits from WebControl and implements IValidator, but I
I have a custom control: it's managed code, which subclasses System.Windows.Forms.Control. I want to
I have a question about creating and managing events inside an ascx custom web
I have a custom control which has a property of type Collection<System.Drawing.Point> . When
I have a simple user control that contains some buttons that fire events which
I have a custom ASCX control that is not visible in design mode in
I have a custom .ascx control and would like to set one of it's
I have a custom control which has a RadioButtonList control in it. On selecting

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.