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. Need help in Javascript

Need help in Javascript

Scheduled Pinned Locked Moved ASP.NET
javascriptdockerhelp
4 Posts 3 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi I created an UserControl, it contains two container controls. First container contains DropDownList1,TextBox1 and second Container contains DropDownList2,TextBox2. I added this usercontrol to the webform and the control name is ctl Now in javascript I want to set the TextBox2 value as the DropDownList1.Selectedvalue and TextBox1 value as the DropDownList2.Selectedvalue. Now i am using this code in JavaScript, this.form['_ctl0:DropDownList1:Text'].value = this.form['_ctl0:DropDownList2:Text'].options[this.selectedIndex].value; but if I place the same user control twice in the webform it wont work, so i want generic code to set the textbox values.

    S 1 Reply Last reply
    0
    • L Lost User

      Hi I created an UserControl, it contains two container controls. First container contains DropDownList1,TextBox1 and second Container contains DropDownList2,TextBox2. I added this usercontrol to the webform and the control name is ctl Now in javascript I want to set the TextBox2 value as the DropDownList1.Selectedvalue and TextBox1 value as the DropDownList2.Selectedvalue. Now i am using this code in JavaScript, this.form['_ctl0:DropDownList1:Text'].value = this.form['_ctl0:DropDownList2:Text'].options[this.selectedIndex].value; but if I place the same user control twice in the webform it wont work, so i want generic code to set the textbox values.

      S Offline
      S Offline
      Syed Abdul Khader
      wrote on last edited by
      #2

      You generate the javaascript in page cs file instead of hardcoding in the aspx page like this. string jsStr = "this.form['" + yourControlVar.UniqueId + "']. value..."

      U 1 Reply Last reply
      0
      • S Syed Abdul Khader

        You generate the javaascript in page cs file instead of hardcoding in the aspx page like this. string jsStr = "this.form['" + yourControlVar.UniqueId + "']. value..."

        U Offline
        U Offline
        User 1804931
        wrote on last edited by
        #3

        Hi, In my user control, I have two DropDownList boxes(two instances of DropDownList user control) and this DropDownList box itself an usercontrol. It is not possible to set from the .cs file. I want to set it from JavaScript only. Reagrds, Chakravarthy.v

        S 1 Reply Last reply
        0
        • U User 1804931

          Hi, In my user control, I have two DropDownList boxes(two instances of DropDownList user control) and this DropDownList box itself an usercontrol. It is not possible to set from the .cs file. I want to set it from JavaScript only. Reagrds, Chakravarthy.v

          S Offline
          S Offline
          Syed Abdul Khader
          wrote on last edited by
          #4

          I created User Controls WebUserControl1 which contains a button. Another UserControl WebUserControl2 which contains the WebUserControl1. I am using the WebUserControl2 instance in a page. I added javascript code for click event of the Button in the page hosting the WebUserControl2. It is working perfectly. protected override void OnPreRender(EventArgs e) { base.OnPreRender (e); Button btn = (Button) this.WebUserControl21 .FindControl("WebUserControl11").FindControl("Button1"); string jsStr = "alert('" + btn.UniqueID + "');return false;"; btn.Attributes.Add("onclick", jsStr); }

          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