Thursday, April 7, 2011

Script control 'ControlName' is not a registered script control

So you're here because you got the following error.

Script control 'ControlName' is not a registered script control. Script controls must be registered using RegisterScriptControl() before calling RegisterScriptDescriptors().

Parameter name: scriptControl


I myself have done a fair bit of googling on this, and there are many solutions given all over the net. unfortunately these are all very scenario specific solutions. Some people get their answers, and the others, like me, don't.

Answer:

You are changing the visibility of a control at the wrong stage of the page life cycle.

Description:

If you are changing the visibility of a control, you should always do it during, or before the PreRender event. If you do it after (i.e. in a End handler of an async task or during PreRenderComplete) you might run in to this issue.

This is not an issue for simple controls such as buttons or text boxes. But it will have adverse effects on controls such as grids.

When I say changing the visibility it could be any one of the following situations

  • Having visible=false of a control during the early stages of the life cycle and being changed to visible=true during an end handler or PreRenderComplete
  • Changing the selected view of a MultiView during an end handler or PreRenderComplete
  • Any other situation where the control may not be visible during the earlier stages of the page life cycle which are set to be visible during the latter stage
Reason:
Purely from my understanding, ASP.NET does not render the scripts or the HTML related to a control if it is not being shown to the user. The registering of script controls which is mentioned in the exception seem to happen during an early stage of the life cycle. if the control is not visible at this stage, this registration is skipped for that control. If it's made to be visible at a latter point, you get yourself a control without some of the relevant scripts.

Anyway this is what I have understood. I may be wrong. But if you come across this issue, it will definitely help you to check for controls which are changing visibility at different points of the life cycle. You will be able to identify your specific problem by doing this and then come up with a solution on your own.

Hope this information helps some one.

7 comments:

  1. Thanks, this helped me a lot!

    ReplyDelete
  2. Bingo. The problem you described was exactly my issue. User control with AJAX having it's visibility changed in the PreRenderComplete event, changed it to PreRender and it works great now.

    Thanks for sharing!

    ReplyDelete
  3. Interesting! we had the same problem and making our visibility false in init and was getting the problem. Changing it to pre_render did not solve the problem. Only changing it to prerendercomplete fixed the problem

    ReplyDelete
    Replies
    1. Thing is you could make visibility=false during prerender or prerendercomplete. but if you have visibility = false during early stages, you cannot make visibility = true during prerender or prerender complete

      Delete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Guys, how do I change the values? I have been looking for a way to get it done, there is a lot of info but nothing clear

    ReplyDelete
  6. I posted my question here, can you please look on this...
    https://stackoverflow.com/questions/42256590/how-to-send-chart-control-in-email-using-c-sharp-asp-net

    ReplyDelete