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. Client Generated IDs and JavaScript

Client Generated IDs and JavaScript

Scheduled Pinned Locked Moved ASP.NET
javascripthtmldatabasesysadmindata-structures
3 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.
  • V Offline
    V Offline
    Vasudevan Deepak Kumar
    wrote on last edited by
    #1

    Hi, When we use HtmlControls or WebControls with runat=server, server automatically generates the required StyleSheets, JavaScripts etc, but the ID is now regenerated as _ctl13_txtName :confused::confused: If we restrict ourselves to RequiredFieldValidators and/or serverside validation and throw a message, everything is okay? But if we need to append our custom JavaScript for any of the elements, then comes how to access individual elements. I have been trying out the following shortcut. After </form> I insert some script language javascript to be executed on window.onLoad to get the index of the form elements that I need to access in my scripts. Then I do a eval("document.myform.elements["+indexValue+"]").value I am not sure whether this is a right solution or is there a better solution for this problem. Perhaps we can also use getElementById() but is it not heavy for the browser since again constructing a DOM tree etc? Please advise... Deepak Kumar Vasudevan http://deepak.portland.co.uk/

    M 1 Reply Last reply
    0
    • V Vasudevan Deepak Kumar

      Hi, When we use HtmlControls or WebControls with runat=server, server automatically generates the required StyleSheets, JavaScripts etc, but the ID is now regenerated as _ctl13_txtName :confused::confused: If we restrict ourselves to RequiredFieldValidators and/or serverside validation and throw a message, everything is okay? But if we need to append our custom JavaScript for any of the elements, then comes how to access individual elements. I have been trying out the following shortcut. After </form> I insert some script language javascript to be executed on window.onLoad to get the index of the form elements that I need to access in my scripts. Then I do a eval("document.myform.elements["+indexValue+"]").value I am not sure whether this is a right solution or is there a better solution for this problem. Perhaps we can also use getElementById() but is it not heavy for the browser since again constructing a DOM tree etc? Please advise... Deepak Kumar Vasudevan http://deepak.portland.co.uk/

      M Offline
      M Offline
      manishgour
      wrote on last edited by
      #2

      Perhaps this is what u want... This sample is from .net sdk documentation. void Page_Load(Object sender, EventArgs e) { TextBox1.Attributes["onblur"]="javascript:alert('Hello! Focus lost from text box!!');"; }

      Attributes Property of a Web Control

      V 1 Reply Last reply
      0
      • M manishgour

        Perhaps this is what u want... This sample is from .net sdk documentation. void Page_Load(Object sender, EventArgs e) { TextBox1.Attributes["onblur"]="javascript:alert('Hello! Focus lost from text box!!');"; }

        Attributes Property of a Web Control

        V Offline
        V Offline
        Vasudevan Deepak Kumar
        wrote on last edited by
        #3

        Hi Manish, Adding JavaScript function from CodeBehind is okay with me. But my actual problem was managing with the dynamically generated IDs for the control. Deepak Deepak Kumar Vasudevan http://deepak.portland.co.uk/

        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