how to know id of dynamically created web server control on client side using javascript when sever control is on aspx page & that aspx page in MasterPage
-
Hello All, Can someone help me in finding Id of dynamically created webserver control like textbox, dropdownlist etc, when these server control placed in aspx page, but the aspx page is included in Master page. Suppose dynamically created textbox textbox1 id changes to clt100_Main_textbox1 How to find out this id or its value using javascript Please help in this regard. Solution will be appreciated. Regards Balasaheb:)
Balasaheb Software Developer Platform: Asp.net,vb.net Database: SQL Server 2000
-
Hello All, Can someone help me in finding Id of dynamically created webserver control like textbox, dropdownlist etc, when these server control placed in aspx page, but the aspx page is included in Master page. Suppose dynamically created textbox textbox1 id changes to clt100_Main_textbox1 How to find out this id or its value using javascript Please help in this regard. Solution will be appreciated. Regards Balasaheb:)
Balasaheb Software Developer Platform: Asp.net,vb.net Database: SQL Server 2000
-
You can access the server control in javascript by its property called "clientid" so in aspx assign a variable with the clientid of the textbox(or any server control) ex: var ctrid=<%= TextBox1.ClientId %>; and use it. Yogesh.
Thanks for ur reply you r right, & I do same think in my application for all pages on which server controls are placed directly rather than created dynamically. But for dynamically created ctrl (For now, I'll say only ctrl for dynamic server controls), javascript function which I called unable to find out ctrl name like ctl100_Main_textbox1 Textbox textbox1 = new TextBox1(); textbox1.Attributes.Add("OnMouseOver","FunTest("+ textbox1.ClientID + ")"); Function FunTest(obj) { var a = document.getElementById(obj); return a; } above javascript function return null even control is present on page. Can u help me in this regard Balasaheb
Balasaheb Software Developer Platform: Asp.net,vb.net Database: SQL Server 2000
-
Thanks for ur reply you r right, & I do same think in my application for all pages on which server controls are placed directly rather than created dynamically. But for dynamically created ctrl (For now, I'll say only ctrl for dynamic server controls), javascript function which I called unable to find out ctrl name like ctl100_Main_textbox1 Textbox textbox1 = new TextBox1(); textbox1.Attributes.Add("OnMouseOver","FunTest("+ textbox1.ClientID + ")"); Function FunTest(obj) { var a = document.getElementById(obj); return a; } above javascript function return null even control is present on page. Can u help me in this regard Balasaheb
Balasaheb Software Developer Platform: Asp.net,vb.net Database: SQL Server 2000
In this particular case try use like Textbox textbox1 = new TextBox1(); textbox1.Attributes.Add("OnMouseOver","FunTest(this)"); and "this" will give the object and you can use in ur "Funtext" function... like obj.value 'No need of getElementById try this.... Sorry if i am wrong.... Yogesh -- modified at 2:47 Friday 30th March, 2007
-
In this particular case try use like Textbox textbox1 = new TextBox1(); textbox1.Attributes.Add("OnMouseOver","FunTest(this)"); and "this" will give the object and you can use in ur "Funtext" function... like obj.value 'No need of getElementById try this.... Sorry if i am wrong.... Yogesh -- modified at 2:47 Friday 30th March, 2007
I'll try and get back to u. Before that, I want to explain another situation. The javascript function which is working perfectly for physical page (not dynamic) function callcal(obj,objTxt) { //alert(obj.id + " " + objTxt); var curleft = curtop = 0; if (obj.offsetParent) { curleft = obj.offsetLeft curtop = obj.offsetTop while (obj = obj.offsetParent) { curleft += obj.offsetLeft curtop += obj.offsetTop } } //var objtxtid = document.getElementById(objTxt); //alert(objTxt + " " + objtxtid ); var x= document.getElementById(objTxt).value ; var y= document.forms[0].name; window.open("DatePicker.aspx?Form="+ y + "&Field="+objTxt+"&Value=" + x + "&hField=<%=hfTargetResponsedate.ClientID %>","","top="+ curtop +", left= "+ curleft +" width=280, height=190, status=0"); return false; } Here u find objTxt & x. Forget about IF part inside function, just concentrate on 'x=' part. The x returns null on function call. Now how this function gets called? string strImage = ""; strImage = strImage + " "; HtmlAnchor objAnc = new HtmlAnchor(); objAnc.ID = "lnkDate" + strCtrlID; //objAnc.Name = strCtrlID; objAnc.InnerHtml = strImage; objAnc.Style.Add("text-decoration", "none"); //txtTargetResponseDate objAnc.Attributes.Add("onclick", "javascript:return callcal(this,'" + txtloc.ClientID + "')"); clChield2.Controls.Add(objAnc); Look for callcal function above for objAnc and I send clientID of textbox which is dynamically created. Please let me know about ur view/solution Regards Balasaheb:) By click on image, it should open popup with proper page size
Balasaheb Software Developer Platform: Asp.net,vb.net Database: SQL Server 2000
-
I'll try and get back to u. Before that, I want to explain another situation. The javascript function which is working perfectly for physical page (not dynamic) function callcal(obj,objTxt) { //alert(obj.id + " " + objTxt); var curleft = curtop = 0; if (obj.offsetParent) { curleft = obj.offsetLeft curtop = obj.offsetTop while (obj = obj.offsetParent) { curleft += obj.offsetLeft curtop += obj.offsetTop } } //var objtxtid = document.getElementById(objTxt); //alert(objTxt + " " + objtxtid ); var x= document.getElementById(objTxt).value ; var y= document.forms[0].name; window.open("DatePicker.aspx?Form="+ y + "&Field="+objTxt+"&Value=" + x + "&hField=<%=hfTargetResponsedate.ClientID %>","","top="+ curtop +", left= "+ curleft +" width=280, height=190, status=0"); return false; } Here u find objTxt & x. Forget about IF part inside function, just concentrate on 'x=' part. The x returns null on function call. Now how this function gets called? string strImage = ""; strImage = strImage + " "; HtmlAnchor objAnc = new HtmlAnchor(); objAnc.ID = "lnkDate" + strCtrlID; //objAnc.Name = strCtrlID; objAnc.InnerHtml = strImage; objAnc.Style.Add("text-decoration", "none"); //txtTargetResponseDate objAnc.Attributes.Add("onclick", "javascript:return callcal(this,'" + txtloc.ClientID + "')"); clChield2.Controls.Add(objAnc); Look for callcal function above for objAnc and I send clientID of textbox which is dynamically created. Please let me know about ur view/solution Regards Balasaheb:) By click on image, it should open popup with proper page size
Balasaheb Software Developer Platform: Asp.net,vb.net Database: SQL Server 2000
-
ok .. as u have passed "this" i.e object totally to function use it x= obj.value; ================ anyway as of ur function it should work!!!
I got the solution. If developer is using dynamic control,then they should use control's Prerender event in order to send object of these controls to javascript. Suppose ur activating Popup on click of Image img, then img_PreRender event should be used. Image img = new Image(); img.ClientId ="imgABC" img.ImageUrl="abc.jpg"; img.PreRender += new EventHandler(img_PreRender); void o_PreRender(object sender, EventArgs e) { string str = imgABC.ClientId; //here u can access any control ClinetId. } Regards Balasaheb
Balasaheb Software Developer Platform: Asp.net,vb.net Database: SQL Server 2000