C
Chris
Hi,
i have in an content page a fieldset containing a label, an iframe and a
textarea:
<asp:Content ID="Content1" ContentPlaceHolderID="main" Runat="Server">
<fieldset style="width:650px;">
<asp:Label ID="Label1" runat="server"></asp:Label>
<iframe ..... ></iframe>
<textarea id="txta" rows="6" onkeypress="return
mysub(event)"></textarea>
</fieldset>
</asp:Content>
In order to send the text, the user must press the ENTER key.
What i'm trying to do is to give the focus to the textarea.
I did this in code-behind:
Dim ta As HtmlTextArea
Dim mp As Content
mp = FindControl("Content1")
ta = mp.FindControl("txta")
ta.Focus()
but this gives the error: "Object reference not set to an instance of an
object. " for line ta = mp.FindControl("txta")
(I use textarea instead of asp:textbox because i need the ONKEYPRESS event,
which is not available with textbox).
I then tried with runat="server" in the textarea tag and that allows me to
put the focus straightfully like this: txta.focus(), but then, when pressing
Return on the keyboard, i get a javascript error (because the onkeypress
event is no longer available).
So, i have to choose between having the focus on textarea or the Onkeypress
event.
Anyway to get both of them together?
Thanks Chris
i have in an content page a fieldset containing a label, an iframe and a
textarea:
<asp:Content ID="Content1" ContentPlaceHolderID="main" Runat="Server">
<fieldset style="width:650px;">
<asp:Label ID="Label1" runat="server"></asp:Label>
<iframe ..... ></iframe>
<textarea id="txta" rows="6" onkeypress="return
mysub(event)"></textarea>
</fieldset>
</asp:Content>
In order to send the text, the user must press the ENTER key.
What i'm trying to do is to give the focus to the textarea.
I did this in code-behind:
Dim ta As HtmlTextArea
Dim mp As Content
mp = FindControl("Content1")
ta = mp.FindControl("txta")
ta.Focus()
but this gives the error: "Object reference not set to an instance of an
object. " for line ta = mp.FindControl("txta")
(I use textarea instead of asp:textbox because i need the ONKEYPRESS event,
which is not available with textbox).
I then tried with runat="server" in the textarea tag and that allows me to
put the focus straightfully like this: txta.focus(), but then, when pressing
Return on the keyboard, i get a javascript error (because the onkeypress
event is no longer available).
So, i have to choose between having the focus on textarea or the Onkeypress
event.
Anyway to get both of them together?
Thanks Chris