Welcome Guest Search | Active Topics | Sign In | Register

Another callback panel issue Options
paul
Posted: Monday, July 2, 2007 2:32:27 AM
Rank: Member
Groups: Member

Joined: 6/21/2007
Posts: 15
Ok here is an interesting problem for you.
Let say we are creating a mini chat app.
We have a callback panel with several controls on it.

a panel that acts as a scrolling container.
a label inside the panel which will display the chat data
a textbox to enter new data
and a button to send the data


Next we add a client side javascript on a timer to run the callback.execute at regular intervals to read the lastest data from the database and add it to the label control.

i.e.
client side script
<body onload="clock()">
<form id="form1" runat="server">
<SCRIPT LANGUAGE='JavaScript'>
<!-- Begin
function clock() {
eo_Callback('callback1', 'test')
setTimeout("clock()", 3000);
}
// End -->
</script>

and the codebehind
Protected Sub callback1_Execute(ByVal sender As Object, ByVal e As EO.Web.CallbackEventArgs) Handles callback1.Execute
dim sqltemp as string=""
sqltemp="select top 50 from chattbl"
myreader=runsqlquery(sqltemp)
while myreader.read()
'repopulate label control with the lastest 50 rows from the database.
end while
myreader.close
End Sub

We also tell the callback control to execute on the button click action. We add a click event to the buttton so when clicked it will add the contents of the textbox to the label control and clear the textbox.

i.e.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Label1.Text = TextBox2.Text + "<br>" + Label1.Text
TextBox2.Text = ""
End Sub

Ok now the problem. At any time the timer executes its code the textbox looses its focus.
I even attempted to add a client side script to reset the focus back to the textbox and told the callback control to run "afterclientsideupdate setMessageFocus()".

i.e.
client side script
function setMessageFocus() {
if (typeof document.frmControl != 'undefined' && typeof document.frmControl.textBox2 != 'undefined')
{
document.frmControl.textBox2.focus();
}
}

and this did not work either.
Next I tried to tell the callback.execute to reset the focus.

i.e.
Protected Sub callback1_Execute(ByVal sender As Object, ByVal e As EO.Web.CallbackEventArgs) Handles callback1.Execute
textbox2.focus()
end sub

and this did not work either.

Next I removed the textbox from the callback panel altogether and it kept the focus but after I clicked the button it did not clear the textbox but it did add the text from it to the label control.
I tried everything to get it to clear the textbox but nothing worked.

Any ideas to either get it to clear the textbox or with the textbox on the callback panel to maintain the focus?
eo_support
Posted: Monday, July 2, 2007 8:40:01 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
hey, Paul

Yeah, looks like it is an interesting problem.
I tried exactly what you said, and in the first approach, same as you, it could not keep the focus. The Callback Panel also did something else after "afterclientsideupdate ".
But in the second approach, I moved both textbox and the send button out from the Callback Panel, seems it works. It can keep the focus and update the label as well. When you click Send, it works fine too. If you want to put the focus back to textbox after Send clicked, you can put one line TextBox2.Focus(); in the Page_Load handler.
You can try it and let me know how it goes on yours.

Thanks.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.