Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 12, 2008 10:15 AM by imperialx
Member
523 Points
1220 Posts
Aug 08, 2008 09:40 AM|LINK
Hello,
Why I can't pass the value to a Label control from a TextArea control? [:(]
...
<script language="JavaScript" type="text/javascript"> function submitForm() { document.getElementById('HiddenField1').value = document.form1.area1.value; return false; } </script>
<form id="form1" runat="server"> <div> <textarea name="area1" style="width: 300px; height: 100px;"></textarea><br /> <asp:HiddenField ID="HiddenField1" runat="server" /> <asp:Label ID="Label1" runat="server" Text="Label" /> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="submitForm()" /> </div> </form>
Protected Sub Button1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Load Label1.Text = HiddenField1.Value End Sub
Regards,
imperialx
Contributor
4907 Points
836 Posts
Aug 08, 2008 12:48 PM|LINK
Put runat="server" in textarea tag.
U can then access it from codebehind.
Star
12771 Points
2361 Posts
Aug 08, 2008 03:06 PM|LINK
You don't really use textarea anymore either, you use a textbox set its properties to multiline and it behaves just like a textarea
All-Star
45968 Points
2997 Posts
Aug 11, 2008 08:39 AM|LINK
imperialx Hello, Why I can't pass the value to a Label control from a TextArea control? ... <script language="JavaScript" type="text/javascript"> function submitForm() { document.getElementById('HiddenField1').value = document.form1.area1.value; return false; } </script> <form id="form1" runat="server"> <div> <textarea name="area1" style="width: 300px; height: 100px;"></textarea><br /> <asp:HiddenField ID="HiddenField1" runat="server" /> <asp:Label ID="Label1" runat="server" Text="Label" /> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="submitForm()" /> </div> </form> Protected Sub Button1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Load Label1.Text = HiddenField1.Value End Sub ... Regards, imperialx
Why I can't pass the value to a Label control from a TextArea control?
Hi imperialx,
Actually, the code you posted is working very well with me.
So, build a new page and have another try on it. Or, just use a multiline TextBox as what DarthSwian said above.
Best Regards, Shengqing Yang
Aug 12, 2008 08:08 AM|LINK
Hi, Yes you are right It is working well but why do I keep clcking the button TWICE? Have you experience this on your part while using the code above?
Aug 12, 2008 08:17 AM|LINK
imperialx Hi, Yes you are right It is working well but why do I keep clcking the button TWICE? Have you experience this on your part while using the code above?
I just noticed that you used Button_Load event in your code above. However, I used Button_Click instead.
So, is there any special reason that you need to fire the event at the time Button loaded?
Aug 12, 2008 08:39 AM|LINK
Hi Shengqing! That's a quick reply anyways I'm still getting the same double click whether I put it on click event or not. [:(]
Actually, I'm trying the WYSIWYG from NicEdit and below is the complete code I use while using their feature.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="niceEdit.aspx.vb" Inherits="niceEdit" EnableEventValidation="false" ValidateRequest="false" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>niceEdit</title> <script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script> <script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script> <script language="JavaScript" type="text/javascript"> function submitForm() { document.getElementById('HiddenField1').value = document.form1.ctl02.value; return false; } </script> </head> <body> <form id="form1" runat="server"> <div> <textarea name="area1" runat="server" style="width: 300px; height: 100px;"></textarea><br /> <asp:HiddenField ID="HiddenField1" runat="server" /> <asp:Label ID="Label1" runat="server" Text="Label" /> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="submitForm()" /> </div> </form> </body> </html>
Aug 12, 2008 09:04 AM|LINK
Here may be the problem in JavaScript.
<script language="JavaScript" type="text/javascript"> function submitForm() { document.getElementById('HiddenField1').value = document.form1.ctl02.value; return false; } </script>
And have you tried on the code like below?
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Label1.Text = Textarea1.Value End Sub
I am just using it and it works fine with me.
Aug 12, 2008 09:37 AM|LINK
Hi Shengqing,
I use 'ctlo2' because it was generated by .net automatically by checking at view source.
Here is the code-behind;
Partial Class niceEdit Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Label1.Text = HiddenField1.Value End Sub End Class
Aug 12, 2008 10:06 AM|LINK
I have tested your code and face the same problem with you.
Here is my research.
I add the statment "alert(document.getElementById('Textarea1').value)" at the end of JavaScript function and find it gets no value from the Textarea.
But if I comment out these two lines:
<script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script> <script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script>
It works well.
So I think the problem might be caused by the third party control you are using.
Here is the solution:
You just need to use these VB.Net code to get the value in the Textarea. And it works fine with me.
imperialx
Member
523 Points
1220 Posts
Submit value from TextArea
Aug 08, 2008 09:40 AM|LINK
Hello,
Why I can't pass the value to a Label control from a TextArea control? [:(]
...
<script language="JavaScript" type="text/javascript">
function submitForm() {
document.getElementById('HiddenField1').value = document.form1.area1.value;
return false;
}
</script>
<form id="form1" runat="server">
<div>
<textarea name="area1" style="width: 300px; height: 100px;"></textarea><br />
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Label ID="Label1" runat="server" Text="Label" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="submitForm()" />
</div>
</form>
Protected Sub Button1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Load
Label1.Text = HiddenField1.Value
End Sub
...
Regards,
imperialx
yeotumitsu@s...
Contributor
4907 Points
836 Posts
Re: Submit value from TextArea
Aug 08, 2008 12:48 PM|LINK
Put runat="server" in textarea tag.
U can then access it from codebehind.
-Manas
=======================================
If this post is useful to you, please mark it as answer.
DarthSwian
Star
12771 Points
2361 Posts
Re: Submit value from TextArea
Aug 08, 2008 03:06 PM|LINK
You don't really use textarea anymore either, you use a textbox set its properties to multiline and it behaves just like a textarea
Seek and ye shall find or http://lmgtfy.com/
Shengqing Ya...
All-Star
45968 Points
2997 Posts
Re: Submit value from TextArea
Aug 11, 2008 08:39 AM|LINK
Hi imperialx,
Actually, the code you posted is working very well with me.
So, build a new page and have another try on it. Or, just use a multiline TextBox as what DarthSwian said above.
Best Regards,
Shengqing Yang
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework
imperialx
Member
523 Points
1220 Posts
Re: Submit value from TextArea
Aug 12, 2008 08:08 AM|LINK
Hi, Yes you are right It is working well but why do I keep clcking the button TWICE? Have you experience this on your part while using the code above?
Shengqing Ya...
All-Star
45968 Points
2997 Posts
Re: Submit value from TextArea
Aug 12, 2008 08:17 AM|LINK
Hi imperialx,
I just noticed that you used Button_Load event in your code above. However, I used Button_Click instead.
So, is there any special reason that you need to fire the event at the time Button loaded?
Best Regards,
Shengqing Yang
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework
imperialx
Member
523 Points
1220 Posts
Re: Submit value from TextArea
Aug 12, 2008 08:39 AM|LINK
Hi Shengqing! That's a quick reply anyways I'm still getting the same double click whether I put it on click event or not. [:(]
Actually, I'm trying the WYSIWYG from NicEdit and below is the complete code I use while using their feature.
...
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="niceEdit.aspx.vb" Inherits="niceEdit"
EnableEventValidation="false" ValidateRequest="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>niceEdit</title>
<script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>
<script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script>
<script language="JavaScript" type="text/javascript">
function submitForm() {
document.getElementById('HiddenField1').value = document.form1.ctl02.value;
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<textarea name="area1" runat="server" style="width: 300px; height: 100px;"></textarea><br />
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Label ID="Label1" runat="server" Text="Label" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="submitForm()" />
</div>
</form>
</body>
</html>
...
Regards,
imperialx
Shengqing Ya...
All-Star
45968 Points
2997 Posts
Re: Submit value from TextArea
Aug 12, 2008 09:04 AM|LINK
Hi imperialx,
Here may be the problem in JavaScript.
I haven't found "ctl02" in your HTML codes.And have you tried on the code like below?
I am just using it and it works fine with me.
Best Regards,
Shengqing Yang
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework
imperialx
Member
523 Points
1220 Posts
Re: Submit value from TextArea
Aug 12, 2008 09:37 AM|LINK
Hi Shengqing,
I use 'ctlo2' because it was generated by .net automatically by checking at view source.
Here is the code-behind;
Partial Class niceEdit
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = HiddenField1.Value
End Sub
End Class
Shengqing Ya...
All-Star
45968 Points
2997 Posts
Re: Submit value from TextArea
Aug 12, 2008 10:06 AM|LINK
Hi imperialx,
I have tested your code and face the same problem with you.
Here is my research.
I add the statment "alert(document.getElementById('Textarea1').value)" at the end of JavaScript function and find it gets no value from the Textarea.
But if I comment out these two lines:
It works well.
So I think the problem might be caused by the third party control you are using.
Here is the solution:
You just need to use these VB.Net code to get the value in the Textarea. And it works fine with me.
Best Regards,Shengqing Yang
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework