[英]How can I use/reference the selected value (TextBox) from a JavaScript Function into C# Code behind?
<script type="text/javascript">
$(function () {
//ALPHA
$('#COLOR_ALPHA_TEXTBOX1').colorPicker({ pickerDefault: "E1E1E1", colors: ["E1E1E1", "33CC00", "FFF000", "CC0000", "996600", "FF9900", "303030", "0066FF", "F9A7B0", "9A0EEA"], transparency: true });
$('#COLOR_ALPHA_TEXTBOX2').colorPicker({ pickerDefault: "E1E1E1", colors: ["E1E1E1", "33CC00", "FFF000", "CC0000", "996600", "FF9900", "303030", "0066FF", "F9A7B0", "9A0EEA"], transparency: true });
});
</script>
<asp:Table ID="Table" runat="server" style="border: medium solid #000000">
<asp:TableRow>
<asp:TableCell ID="TC2BC" HorizontalAlign="left" VerticalAlign="top">
<asp:TextBox ID="COLOR_ALPHA_TEXTBOX1" type="text" runat="server" Visible="False"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ID="TC9BC" HorizontalAlign="left" VerticalAlign="top" >
<asp:TextBox ID="COLOR_ALPHA_TEXTBOX2" type="text" runat="server" Visible="False"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
I tried to use on the code behind cs: 我试图在cs后面的代码上使用:
COLOR_ALPHA_TEXTBOX1.SelectedValue
But, I don't get that option in C#; 但是,我在C#中没有得到该选项。 What could be an alternative?
有什么替代方案? Thanks so much for the help!
非常感谢你的帮助!
First of all fix ASPX markup, the first </asp:TableRow>
should be <asp:TableRow>
otherwise tags won't match. 首先修复ASPX标记,第一个
</asp:TableRow>
应该是<asp:TableRow>
否则标记将不匹配。
Second, TextBox
doesn't have SelectedValue
property, it has Text
propetrty. 其次,
TextBox
没有SelectedValue
属性,它具有Text
属性。
And third - you cannot access inner nested control directly, you have to use FindControl to find it: 第三,您不能直接访问内部嵌套控件,而必须使用FindControl来找到它:
(TextBox)Table.Rows[0].Cells[0].FindControl("COLOR_ALPHA_TEXTBOX1").Text
why are you trying to get the selected value of a textbox? 为什么要尝试获取文本框的选定值? You should be using
您应该使用
COLOR_ALPHA_TEXTBOX1.Text
in the codebehind. 在后面的代码中。
Also, don't use 另外,请勿使用
Visible="false"
as this will cause the control to not be rendered. 因为这将导致控件无法呈现。 if you want to hide a control (not sure why you would here, though) use:
如果要隐藏控件(尽管不确定为什么会在这里),请使用:
style="display:none"
Are you using another library with this control? 您是否正在使用带有此控件的另一个库? I don't see how you can be using a "color" picker without more code.
我看不出没有更多代码如何使用“颜色”选择器。 Are you using jQuery or the AjaxControlToolkit?
您正在使用jQuery还是AjaxControlToolkit?
This issue is usually caused by one of two things: 此问题通常是由以下两种原因之一引起的:
System.UI.Page
System.UI.Page
继承的 codebehind
attribute: codebehind
属性中没有正确的值: <%@ Page Language="vb" AutoEventWireup="false" Codebehind="InheritSample.aspx.vb" Inherits="CodeBehindSamples.InheritSample"%>
however for a textbox SelectedValue
is the wrong property, if you want its text you should be using Text
: 但是,对于文本框,
SelectedValue
是错误的属性,如果要使用其文本,则应使用Text
:
COLOR_ALPHA_TEXTBOX1.Text
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.