admin管理员组文章数量:1023744
This the code in my .aspx page and I am using auto plete for textbox.
<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$(".autosuggest").autoplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Preferences.aspx/GetAutoCompleteData",
data: "{'Name':'" + document.getElementById('txtSearch').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});
}
</script>
<table style="width:auto">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Please Type Student Name:"></asp:Label>
</td>
<td>
<input type="text" id="txtSearch" class="autosuggest" />
<asp:TextBox ID="TextBox1" runat="server" Text=txtsearch Visible="true" class="autosuggest"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
</td>
</tr>
</table>
If I put runat="Server" in
<input type="text" id="txtSearch" class="autosuggest" />
then auto plete doesn't work. Form tag is used in master page.
Problem Solved using the name property of control
Source Code:
<input type="text" name="_name" />
<asp:Button ID="btnShow" runat="server" Text="Show" onclick="btnShow_Click" />
CodeBehind:
protected void btnShow_Click(object sender, EventArgs e)
{
string strValue = Page.Request.Form["_name"].ToString();
Response.Write(strValue);
}
Reference: .html
Thanks guys for your help.
This the code in my .aspx page and I am using auto plete for textbox.
<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$(".autosuggest").autoplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Preferences.aspx/GetAutoCompleteData",
data: "{'Name':'" + document.getElementById('txtSearch').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});
}
</script>
<table style="width:auto">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Please Type Student Name:"></asp:Label>
</td>
<td>
<input type="text" id="txtSearch" class="autosuggest" />
<asp:TextBox ID="TextBox1" runat="server" Text=txtsearch Visible="true" class="autosuggest"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
</td>
</tr>
</table>
If I put runat="Server" in
<input type="text" id="txtSearch" class="autosuggest" />
then auto plete doesn't work. Form tag is used in master page.
Problem Solved using the name property of control
Source Code:
<input type="text" name="_name" />
<asp:Button ID="btnShow" runat="server" Text="Show" onclick="btnShow_Click" />
CodeBehind:
protected void btnShow_Click(object sender, EventArgs e)
{
string strValue = Page.Request.Form["_name"].ToString();
Response.Write(strValue);
}
Reference: http://www.etechpulse./2013/02/get-html-input-controls-value-server.html
Thanks guys for your help.
Share Improve this question edited Oct 8, 2013 at 13:44 sudhansu63 6,2104 gold badges40 silver badges54 bronze badges asked Oct 8, 2013 at 9:05 user2345661user2345661 4253 gold badges8 silver badges14 bronze badges 2- Do you want to cal it in a page load? and check in console are you getting any error? – Just code Commented Oct 8, 2013 at 9:30
- You are performing an ajax operation. This will not re-render your entire page. You will need to load the response values to the control. – Kami Commented Oct 8, 2013 at 9:40
2 Answers
Reset to default 2If you are using MasterPage then ASP will auto generate a name for each control and appends it to your control, In order to get the unique ID of the control you need to use JQuery ClientID.
Put runat="server"
but change your jquery function to (this will retrieve the input by ClientID):
function SearchText() {
$("#<%=txtSearch.ClientID%>").autoplete({
Or as an alternative(suggested by DeeMac) use static ClientIDMode.
For getting value form text box, you need to use server control.
<asp:TextBox ID="txtSearch" runat="server" ></asp:TextBox>
you can also add ClientIDMode= "static" in the server control to retain your id exactly same or you can use $("#<%=txtSearch.ClientID%>")
to get the dynamicaly generated Id.
This the code in my .aspx page and I am using auto plete for textbox.
<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$(".autosuggest").autoplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Preferences.aspx/GetAutoCompleteData",
data: "{'Name':'" + document.getElementById('txtSearch').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});
}
</script>
<table style="width:auto">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Please Type Student Name:"></asp:Label>
</td>
<td>
<input type="text" id="txtSearch" class="autosuggest" />
<asp:TextBox ID="TextBox1" runat="server" Text=txtsearch Visible="true" class="autosuggest"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
</td>
</tr>
</table>
If I put runat="Server" in
<input type="text" id="txtSearch" class="autosuggest" />
then auto plete doesn't work. Form tag is used in master page.
Problem Solved using the name property of control
Source Code:
<input type="text" name="_name" />
<asp:Button ID="btnShow" runat="server" Text="Show" onclick="btnShow_Click" />
CodeBehind:
protected void btnShow_Click(object sender, EventArgs e)
{
string strValue = Page.Request.Form["_name"].ToString();
Response.Write(strValue);
}
Reference: .html
Thanks guys for your help.
This the code in my .aspx page and I am using auto plete for textbox.
<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$(".autosuggest").autoplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Preferences.aspx/GetAutoCompleteData",
data: "{'Name':'" + document.getElementById('txtSearch').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});
}
</script>
<table style="width:auto">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Please Type Student Name:"></asp:Label>
</td>
<td>
<input type="text" id="txtSearch" class="autosuggest" />
<asp:TextBox ID="TextBox1" runat="server" Text=txtsearch Visible="true" class="autosuggest"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
</td>
</tr>
</table>
If I put runat="Server" in
<input type="text" id="txtSearch" class="autosuggest" />
then auto plete doesn't work. Form tag is used in master page.
Problem Solved using the name property of control
Source Code:
<input type="text" name="_name" />
<asp:Button ID="btnShow" runat="server" Text="Show" onclick="btnShow_Click" />
CodeBehind:
protected void btnShow_Click(object sender, EventArgs e)
{
string strValue = Page.Request.Form["_name"].ToString();
Response.Write(strValue);
}
Reference: http://www.etechpulse./2013/02/get-html-input-controls-value-server.html
Thanks guys for your help.
Share Improve this question edited Oct 8, 2013 at 13:44 sudhansu63 6,2104 gold badges40 silver badges54 bronze badges asked Oct 8, 2013 at 9:05 user2345661user2345661 4253 gold badges8 silver badges14 bronze badges 2- Do you want to cal it in a page load? and check in console are you getting any error? – Just code Commented Oct 8, 2013 at 9:30
- You are performing an ajax operation. This will not re-render your entire page. You will need to load the response values to the control. – Kami Commented Oct 8, 2013 at 9:40
2 Answers
Reset to default 2If you are using MasterPage then ASP will auto generate a name for each control and appends it to your control, In order to get the unique ID of the control you need to use JQuery ClientID.
Put runat="server"
but change your jquery function to (this will retrieve the input by ClientID):
function SearchText() {
$("#<%=txtSearch.ClientID%>").autoplete({
Or as an alternative(suggested by DeeMac) use static ClientIDMode.
For getting value form text box, you need to use server control.
<asp:TextBox ID="txtSearch" runat="server" ></asp:TextBox>
you can also add ClientIDMode= "static" in the server control to retain your id exactly same or you can use $("#<%=txtSearch.ClientID%>")
to get the dynamicaly generated Id.
本文标签: cGet value from input box in code behindStack Overflow
版权声明:本文标题:c# - Get value from input box in code behind - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745552754a2155707.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论