I have a master page in which I have the following code.
<head runat="server">
<link href="StyleSheet.css" rel="stylesheet" runat="server" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<asp:contentplaceholder id="LocalScripts" runat="server"></asp:contentplaceholder>
</head>
<body id="body" runat="server">
<form id="form1" runat="server" defaultbutton="SignOutLB">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</form>
</body>
My content page has the following code.
<asp:Content ID="ScriptContent" ContentPlaceHolderID="localScripts" runat="server">
<script type="text/javascript">
function suggest(inputString)
{
if(inputString.length == 0)
{
$('#suggestions').fadeOut();
}
else
{
$('#AAATB').addClass('load');
$.post("AutoSuggest.aspx?ST=" + inputString, function(data){
if(data.length >0)
{
$('#suggestions').fadeIn();
$('#suggestionsList').html(data);
$('#AAATB').removeClass('load');
}
});
}
}
function fill(thisValue)
{
$('#AAATB').val(thisValue);
setTimeout("$('#suggestions').fadeOut();", 600);
}
</script>
</asp:Content>
And the ASP.NET code is as follows.
<asp:TextBox ID="AAATB" runat="server" Width="90px" MaxLength="6" onkeypress="return IsNumberKey(event)" CssClass="textboxStyle" ValidationGroup="projNoValGp" onkeyup="suggest(this.value);" onblur="fill();" />
<div class="suggestionsBox" id="suggestions" style="display: none;">
<img src="Images/arrow.png" style="position: relative; top: -2px; left: 50px;" alt="" />
<div class="suggestionList" id="suggestionsList"> </div>
</div>
My AutoSuggest.aspx has the following piece of code.(I have done this for testing. Once the functionality works, I will change this for retrieving data from the database.)
protected void Page_Load(object sender, EventArgs e)
{
string[] arr = new string[] {
"1234",
"1111",
"1333",
};
for (int i = 0; i < 3; i++)
{
Response.Write("<li onClick=\"fill(\'" + arr[i] + "\');\">" + arr[i] + "</li>");
}
}
This works up to the extent that the values “1234”, “1111”, “1333” are displayed. But when I choose one of these values it is not reflected in the textbox “AAATB”.
I would be grateful for all the help to solve this issue.
Thanks,
Carolina
I think I know. You use ‘#AATB” as selector for the textbox. However, this is a serverside-ID and will be rendered differently on the client.
Try using this as your fill code:
The idea is to use the css-class as selector for the textbox since this isn’t modified.