Masterpage is a new thing in vs.net 2005. It seems that many people have not used it yet. The specific usage of masterpage is explained in more detail in the tutorials.
I encountered a problem when using it, that is, when using JavaScript in the masterpage content page to obtain the Server Control in the content page, the object cannot be obtained.
At that time, my code was like this. For example:
The following sections describe how to use the javasrcipcommand:
Function A () {var txt1 = Document. getelementbyid ("txt1 ");}
The page has only one Textbox, id = txt1;
The above code may cause errors. The debugging information is that JavaScript cannot obtain the object. After debugging, I found that after the page is generated, I checked the source code and found that the textbox ID on the content page will be changed to something like ctl00 $ contentplaceholder1 $ txt1
Therefore, one of the solutions is derived here. I tried to replace txt1 in JavaScript with ctl00 $ contentplaceholder1 $ txt1. The program can work.
However, this will cause a problem. Ctl00 $ contentplaceholder1 $ txt1 is automatically generated by the program. We don't know when the program will change it. There is a lot of reliability in it. If the program changes this ID, the javascript I wrote will not work.
I have been asking this question for a long time on the Javascript version of csdn, and no one can answer it to me.
Fortunately, I found another relatively reliable solution and shared it.
The javascript part is changed to this
Function A () {var txt1 = Document. getelementbyid ("<% = txtvirusname. clientid %> ");}
In this way, you can use it.