Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. 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

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

Scheduled Pinned Locked Moved ASP.NET
databasecsharpjavascriptasp-net
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BalasahebK
    wrote on last edited by
    #1

    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

    N 1 Reply Last reply
    0
    • B BalasahebK

      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

      N Offline
      N Offline
      nyogeswar
      wrote on last edited by
      #2

      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.

      B 1 Reply Last reply
      0
      • N nyogeswar

        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.

        B Offline
        B Offline
        BalasahebK
        wrote on last edited by
        #3

        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

        N 1 Reply Last reply
        0
        • B BalasahebK

          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

          N Offline
          N Offline
          nyogeswar
          wrote on last edited by
          #4

          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

          B 1 Reply Last reply
          0
          • N nyogeswar

            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

            B Offline
            B Offline
            BalasahebK
            wrote on last edited by
            #5

            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

            N 1 Reply Last reply
            0
            • B BalasahebK

              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

              N Offline
              N Offline
              nyogeswar
              wrote on last edited by
              #6

              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!!!

              B 1 Reply Last reply
              0
              • N nyogeswar

                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!!!

                B Offline
                B Offline
                BalasahebK
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups