-1

I've got this piece of code in aspx file.

<form runat="server">

Which shouldn't be complicated. But turns out it is. On my computer and testing enviroment it translates to:

<form id="aspnetForm" ....>

But on production it turns into:

<form id="ctl00" .... >

Big thanks to my predecessor a lot JS is hooked on "aspnetForm" id, and it's not working properly.
So from where does this id generation difference comes from?

P.S. I know that one of solutions just to rewrite JS queries or put class tag on form and query it then. Though im still interested why these things happen.

lew
  • 77
  • 4
  • 11
  • Did you even read question? I'm asking "why **ids** might be generated differently in diferent enviroments". Not why
    id tag is overriden, which doesn't make sense in my case, because there is no tag to start with.
    – lew Jan 27 '14 at 09:28
  • Yes, I did read your question, did you read the one I linked to and its title? A `
    ` tag gets generated for every ASP.NET WebForms page. There are various situations in which this tag gets a generated name, and as explained there: _"**when the naming container is different from the current page** [...] the UniqueID property return "aspnetForm". this property is rendered into the name attribute that is sent to the client in the form tag. so, if you really need to, you can create your own form by inheriting from htmlform and then override the UniqueID property or the Name property"_.
    – CodeCaster Jan 27 '14 at 09:32
  • Also, when the same code behaves differently between testing and production environments, your testing environment most likely doesn't match your production configuration. – CodeCaster Jan 27 '14 at 09:33

2 Answers2

0

You can stop the change using ClientIdMode to Static

शेखर
  • 17,412
  • 13
  • 61
  • 117
  • 1
    he is not asking how to do that. he is asking why it is happening? – pathak tejpal Jan 24 '14 at 11:48
  • This post is potentially helpful as it provides a different solution to what the OP has declared they are aware of, i.e. javascript only solutions. See http://stackoverflow.com/questions/how-to-answer – Paul Zahra Jan 24 '14 at 12:32
-1

Start EDIT

Which version of the .Net framework is used on your pc and test environment and which on server? - This will massively influence the correctness of any answer as to why it is occuring - especially if they are slightly different. And is there only one form on the page?

End EDIT

To get the form name in javascript use the following:

<script>  
    theForms = document.getElementsByTagName("form");  

    for(i=0;i<theForms.length;i++)  
        alert(theForms[i].name);  
</script>

If theres only one form then:

<script>  
    theForms = document.getElementsByTagName("form");  

    alert(theForms[0].name);  
</script>
Paul Zahra
  • 9,522
  • 8
  • 54
  • 76