A major problem found with ASP. NET 2.0 is that getelementbyid cannot be directly used in JavaScript. The ID on the ASP page cannot be referenced directly.
ASP. NET 2.0 name mangling
1: Use
VaR ctrlcust = Document. getelementbyid (<% ctrl. clientid %> );
2: however, if the control is in formview gridview detailview, The findcontrol is required.
Txbox = (textbox) performanceitemview. findcontrol ("textbox ");
Find the control first. Then txbox. clientid, and JavaScript needs to load in page_load
3: but there is still a problem here. In method 2, it is only suitable for default view. If the view has changed, for example, when readonly is converted to edittemplate, the controls in edittemplate use itemview. find cannot be found. Therefore, another method is required. Load Javascript in item_created
What I implement here is a pop-up window that returns a value
Protected void formviewincluitemcreated (Object sender, eventargs E)
{
If (formview1.currentmode = formviewmode. Edit)
{
Textbox custtextbox = (textbox) formview1.findcontrol ("main_customertextbox ");
If (custtextbox = NULL) return;
String JS = "<script language = 'javascript '> ";
JS = JS + "function findcust (custbutton )";
JS = JS + "{";
JS = JS + "Var ttop = custbutton. offsettop ;";
JS = JS + "Var thei = custbutton. clientheight ;";
JS = JS + "Var tleft = custbutton. offsetleft ;";
JS = JS + "while (custbutton = custbutton. offsetparent) {ttop + = custbutton. offsettop; tleft + = custbutton. offsetleft ;}";
JS = JS + "Var returnvalue = Window. showmodaldialog ('.. /common/commonfindcustomer. aspx ', 'pass paramerter to child Window', 'dialogwidth: 600px; dialogheight: 500px; dialogleft:' + tleft + '; dialogtop:' + ttop + '; resizable: yes '); ";
JS = JS +" If (returnvalue = NULL) return; ";
JS = JS + "Var ctrlcust = Document. getelementbyid ('" + custtextbox. clientid + "');";
JS = JS + "If (ctrlcust = NULL )";
JS = JS + "alert ('not found customer control ');";
JS = JS + "else ";
JS = JS + "ctrlcust. value = returnvalue ;";
JS = JS + "} </SCRIPT> ";
Clientscript. registerstartupscript (this. GetType (), "findcustscript", JS );
}
Refer to the following
How to access control in formview
Http://www.dotnettaxi.com/ViewTopic137362.aspx
Formview-findcontrol only works for default view
Http://www.dotnettaxi.com/ViewTopic138828.aspx
Http://west-wind.com/weblog/posts/5127.aspx