Why do my controls get different naming conventions?

I have a gridview with the following template field

<asp:TemplateField> <ItemTemplate> <asp:Button ID="btnLoad" runat="server" Text="Load" CssClass="inptBtn" OnClientClick="return loadPlans(this);" UseSubmitBehavior="false" /> <ItemTemplate> </asp:TemplateField> 

This is working fine. In onclick, we run some code that checks the ID generated by .NET for this control and does everything with it. In the past, the generated identifier looked like this:

gvPlans_ctl02_hdPlans

This is still what is generated in our test environments, but in prod it now looks like this:

gvPlans_hdPlans_0

In both environments, the code is definitely the same, but I'm not sure what causes the naming convention to change. I tried to answer google, but the search terms are a bit generalized for this problem, so I will move on to reliable SO. I guess the answer may have something to do with what kind of infrastructure works or something like that. Please let me know if you have any ideas, thanks!

+4
source share
4 answers

Read this , I think this will help.

+3
source

This is controlled by the ClientIDMode property of the control:

The default value for this can be configured in the web.config file:

Or it can be set for the page in the @Page directive:

+2
source

You can experiment with ClientIDMode if you are using .NET4. But in general, the generated cliend identifier should not matter. You should be able to use control.ClientID in javascript and other places, so as not to refer directly to the generated client identifier, in which case, even if there is a difference in creating a test server with a label created by markup, your code logic should be able to adapt.

+1
source

Check the application pool for this application and the target environment. The target structure seems to be different between prod and dev / text env. Also check the installed frameworks and SP.

0
source

All Articles