The Control ID cannot be obtained from page JS. js gets the Control id.

Source: Internet
Author: User

The Control ID cannot be obtained from page JS. js gets the Control id.

To make pages more friendly, we need to use javascript on pages, so it is very common to use javascript on pages to get control IDs. However, when I recently used JavaScript, I encountered a headache. When I got the Control ID, I encountered an error. monitoring showed that I could not get the control ID.

Source code:

<script type="text/javascript">Function(){            var args = window.dialogArguments;            var serverTaskInfo = $("#hidTaskInfo").val();            if (serverTaskInfo == "") {                BindSelectorControl(args);            } else {                var task = Sys.Serialization.JavaScriptSerializer.deserialize(serverTaskInfo);                BindSelectorControl(task);            }            if (args.action === "readOnly") {                $find("CommonAutoCompleteWithSelectorControl1")._disabled = true;                $find("CommonAutoCompleteWithSelectorControl2")._disabled = true;                $find("CommonAutoCompleteWithSelectorControl1")._ouBtn.disabled = true;                $find("CommonAutoCompleteWithSelectorControl2")._ouBtn.disabled = true;            }        })    </script>

The first analysis may be that the Control ID is wrong, but after comparison, it is found that the name is completely correct, and it does not seem to be a spelling mistake.

If the page does not recognize jquery again, change it to the native javascript to see if it does not work. The result is the same, and the control is displayed as undefined, which is not a language problem.

Baidu doesn't have the answer I want. I found a big bull, said Daniel. It may be that your JS has a problem. During your JS execution, the control you want to obtain has not been rendered on the page, so you cannot get it. (It really is Daniel)

Baidu gave a look at the latest JS execution event on the page. Du Niang's answer is the onload () event. I originally wrote the code directly in function, this may be the reason. Test it in a decisive manner. It is a pity that the Control ID cannot be obtained.

The execution order of the Baidu Page code again shows that the page code is executed in sequence, and the code is tested again and moved to the foot of the Body, that is, at the bottom of the page code, the test results are still unsatisfactory.

Ask Daniel again. Daniel said there was a function execution order that was very late.

Sys.Application.add_load(function() { })
Function.

Try again. The error is reported, but the error prompt is different. Daniel said that it was the same thing to register something and decide Baidu.

<asp:ScriptManager runat="server" ID="scriptManager1" EnableScriptGlobalization="true"        EnablePartialRendering="true"></asp:ScriptManager>

Test again, succeeded!

Complete code:

Where is the registered holy God? It is a script controller used to process all components on the page and partial page updates, and generate relevant client proxy scripts so that you can access the Web Service in JS. It is the basis for the existence of AJAX, if AJAX is used on the page, you must use this controller, and each page can only be used once.

What is this incident? MSDN explanation: triggered after all scripts are loaded and the objects in the application have been created and initialized.




Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.