Results 1 to 7 of 7

Thread: [2005] how to get document.getElementById for a server control in WebUserControl?

  1. #1

    Thread Starter
    Addicted Member senthilkumartd's Avatar
    Join Date
    Feb 2005
    Posts
    206

    [2005] how to get document.getElementById for a server control in WebUserControl?

    Hi,
    Am designing a chat application. It uses IFRAME to display the conversation between users. It is a web user control. I wish to scroll programmatically the content of IFRAME at last on every send button click event. I designed the entire control as a web user control. Any solution to move the content. If you have any better solution it will be appreciated.
    I tried the following,
    Code:
    Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "MyScript", "var x = document.getElementById('" + Me.chatFrame.ID() + "'); alert(x); x.scrolltop=x.scrollHeight", True)
    But the above coding is working but, It displays x is null. so the next statement is not worked. So the scrolling is not happening.
    I tried Me.chatFrame.CleintID instead of me.chatFrame.ID(). but it is not working.

    regards,
    Senthil
    God has been pleased to place as a king or cobbler do the work sincerely

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: [2005] how to get document.getElementById for a server control in WebUserControl?

    Try using clientID instead of ID especially as your control is in a user control you can't always tell what it's ClientID is going to be.
    Code:
    Me.chatFrame.ClientID()

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] how to get document.getElementById for a server control in WebUserControl?

    He said clientID isn't working. Then again, isn't x.scrolltop supposed to be x.scrollTop?

  4. #4
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: [2005] how to get document.getElementById for a server control in WebUserControl?

    Quote Originally Posted by mendhak
    He said clientID isn't working. Then again, isn't x.scrolltop supposed to be x.scrollTop?
    Oops

    Note to self: I must read questions in their entirety.

  5. #5

    Thread Starter
    Addicted Member senthilkumartd's Avatar
    Join Date
    Feb 2005
    Posts
    206

    Re: [2005] how to get document.getElementById for a server control in WebUserControl?

    It is not get the element by id. It shows 'Null'. First of all, the alert should display "object" not as "null". Then only it will take effect for scrolltop=scrollheight
    God has been pleased to place as a king or cobbler do the work sincerely

  6. #6
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: [2005] how to get document.getElementById for a server control in WebUserControl?

    you are missing the semi-colon at the end of the script block:

    should be:
    x.scrolltop=x.scrollHeight; // <-- missing semi-colon

  7. #7
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: [2005] how to get document.getElementById for a server control in WebUserControl?

    I think it should be like this

    Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "MyScript", "function doit() {var x = document.getElementById(" + Me.chatFrame.ClientID + "); alert(x); x.scrollTop=x.scrollHeight;}", True)

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