[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
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()
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?
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 :blush:
Note to self: I must read questions in their entirety.
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
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
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)