Results 1 to 6 of 6

Thread: [RESOLVED] [2005] invalid client id

  1. #1

    Thread Starter
    Fanatic Member vishalmarya's Avatar
    Join Date
    Feb 2001
    Location
    New Delhi , INDIA
    Posts
    858

    Resolved [RESOLVED] [2005] invalid client id

    i am trying to associate "onfocusin" of a textbox ( txt_day ) to a function ( javascript code ) .

    the code works fine if the text box is used directly on a page.

    but if textbox is used in a template column of gridview , javascript error is generated.

    reason for that is the html id of control returned by txt_day.clientid is not same as main tag itself.


    main tage generated is :

    ctl00_ContentPlaceHolder1_DocAttributeValues_GvDocAttributes_ctl04_DC_AttributeValue_txt_day



    id returned by txt_day.clientid is :

    ctl00_ContentPlaceHolder1_DocAttributeValues_GvDocAttributes_ctl02_DC_AttributeValue_txt_day


    below is the complete code :


    Code:
    txt_day.Attributes.Add("onfocusin", "gotfocus()")
    
    
    Dim StrScript As String
    
    StrScript = "<script language=javascript>"
            StrScript = StrScript & "function gotfocus()"
            StrScript = StrScript & "{"
            StrScript = StrScript & "if (document.getElementById('" & txt_day.ClientID & "').value=='day')"
            StrScript = StrScript & "{"
            StrScript = StrScript & "document.getElementById('" & txt_day.ClientID & "').value='';"
            StrScript = StrScript & "}"
            StrScript = StrScript & "}"
            StrScript = StrScript & "</script>"
    
            Page.RegisterStartupScript("gotfocus", StrScript)
    Vishal Marya, MCP .net 3.5
    My Site
    http://www.vstoolsgallery.com/
    http://visualstudiogallery.msdn.micr...b-f87a909b9266





    Please indicate what version of vb you use.
    Please mark your thread resolved using the Thread Tools above.
    -----------------------------------------

  2. #2
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    Re: [2005] invalid client id

    Hi,
    I´m not 100% certain about this but I have the feeling that you make have to modify your javascript for when you use it on the GridView.

    Make your javascript function accept a parameter, which will correspond to the obj, your textbox, which will be firing the event.

    Something like:
    Pass the object raising the event as a parameter.
    Code:
    txt_day.Attributes.Add("onfocusin", "gotfocus(this)")
    Get the id of the object which raised the event.
    Code:
    Dim StrScript As String
    
    StrScript = "<script language=javascript>"
            StrScript = StrScript & "function gotfocus(obj)"
            StrScript = StrScript & "{"
            StrScript = StrScript & "if (document.getElementById('" & obj.ClientID & "').value=='day')"
            StrScript = StrScript & "{"
            StrScript = StrScript & "document.getElementById('" & obj.ClientID & "').value='';"
            StrScript = StrScript & "}"
            StrScript = StrScript & "}"
            StrScript = StrScript & "</script>"
    Not sure whether this part of the code may need to be changed as well.
    Code:
            Page.RegisterStartupScript("gotfocus", StrScript)
    I haven´t tried this out my self!

  3. #3

    Thread Starter
    Fanatic Member vishalmarya's Avatar
    Join Date
    Feb 2001
    Location
    New Delhi , INDIA
    Posts
    858

    Re: [2005] invalid client id

    thanks Rauland .

    for the parameter idea. it worked.

    obj will be passed by the client script , not by the server

    so instead of :
    Code:
    StrScript = StrScript & "if (document.getElementById('" & obj.ClientID & "').value=='day')"
    we have to use

    Code:
     StrScript = StrScript & "if (document.getElementById(obj.id).value=='day')"


    complete code :

    Code:
    txt_day.Attributes.Add("onfocusin", "gotfocus(this)")
    
    
    Dim StrScript As String
    
    StrScript = "<script language=javascript>"
            StrScript = StrScript & "function gotfocus(obj)"
            StrScript = StrScript & "{"
            StrScript = StrScript & "if (document.getElementById(obj.id).value=='day')"
            StrScript = StrScript & "{"
            StrScript = StrScript & "document.getElementById(obj.id).value='';"
            StrScript = StrScript & "}"
            StrScript = StrScript & "}"
            StrScript = StrScript & "</script>"
    
            Page.RegisterStartupScript("gotfocus", StrScript)
    Vishal Marya, MCP .net 3.5
    My Site
    http://www.vstoolsgallery.com/
    http://visualstudiogallery.msdn.micr...b-f87a909b9266





    Please indicate what version of vb you use.
    Please mark your thread resolved using the Thread Tools above.
    -----------------------------------------

  4. #4
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: [RESOLVED] [2005] invalid client id

    You're using document.getElementById, passing the object instance's ID, to get the object's ID. Does that sound ... funny?

    Code:
    function gotfocus(obj) {
      if (obj.value == "day") {
        obj.value = "";
      }
    }

  5. #5
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    Re: [RESOLVED] [2005] invalid client id

    Quote Originally Posted by axion_sa
    You're using document.getElementById, passing the object instance's ID, to get the object's ID. Does that sound ... funny?

    Code:
    function gotfocus(obj) {
      if (obj.value == "day") {
        obj.value = "";
      }
    }
    Your right!

  6. #6

    Thread Starter
    Fanatic Member vishalmarya's Avatar
    Join Date
    Feb 2001
    Location
    New Delhi , INDIA
    Posts
    858

    Re: [RESOLVED] [2005] invalid client id

    Quote Originally Posted by axion_sa
    You're using document.getElementById, passing the object instance's ID, to get the object's ID. Does that sound ... funny?

    Code:
    function gotfocus(obj) {
      if (obj.value == "day") {
        obj.value = "";
      }
    }
    ya it is .

    i just realised that.

    Code:
    txt_day.Attributes.Add("onfocusin", "gotfocus(this)")
    
    
    Dim StrScript As String
    
    StrScript = "<script language=javascript>"
            StrScript = StrScript & "function gotfocus(obj)"
            StrScript = StrScript & "{"
            StrScript = StrScript & "if (obj.value=='day')"
            StrScript = StrScript & "{"
            StrScript = StrScript & "obj.value='';"
            StrScript = StrScript & "}"
            StrScript = StrScript & "}"
            StrScript = StrScript & "</script>"
    
            Page.RegisterStartupScript("gotfocus", StrScript)
    Last edited by vishalmarya; Oct 22nd, 2007 at 01:08 AM.
    Vishal Marya, MCP .net 3.5
    My Site
    http://www.vstoolsgallery.com/
    http://visualstudiogallery.msdn.micr...b-f87a909b9266





    Please indicate what version of vb you use.
    Please mark your thread resolved using the Thread Tools above.
    -----------------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width