Click here to Skip to main content
15,887,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i hav one button and one textbox in myaspx page...values entered in the textbox shoulb b displayed ....once again i entered sm values in the same textbox it shows the nextentered values without disturbing the first and so on....
Posted
Comments
Sandeep Mewara 21-Feb-11 8:28am    
Avoid reposting the same stuff. Follow at one place.

Setting autocomplete to true will do the things for you.
If you wish to autofill from some database or so, check this[^]
 
Share this answer
 
Comments
Sandeep Mewara 21-Feb-11 8:38am    
I doubt if OP is asking this.

Further, it's a repost. Earlier one: http://www.codeproject.com/Questions/160200/values-entered-in-the-textbox-should-b-displayed-d.aspx
Okay for starters you should probably have edited your original question, not posted a new one, however..

Your page should probably contain the following:
1) A div that has an id, call it Values for simplicity and must also have attribute runat="server"
2) An ASP TextBox (which you already have), call this NewValueBox or something
3) An ASP Button (which you already have)

In the button click event do something like the following:

//Set the Session object with the previous values to have the new value as well
//The Session object allows you to store information between requests about a particular user.
Session["Values"] = ((string)Session["Values"]) + NewValueBox.Text + "<br />";

//Set the div inner text to have the previous values and the new value
Values.InnerHtml += ((string)Session["Values"]);

//Set the NewValueBox.Text to empty
NewValueBox.Text = "";


The following is working Html and C# code I have just put together:

HTML
<body>
    <form id="form1" runat="server">
        <div id="ValuesDiv" runat="server">
        </div><br />
    <asp:TextBox ID="NewValueBox" runat="server"></asp:TextBox><br />
    <asp:Button ID="Button1"
        runat="server" Text="Add Value" onclick="Button1_Click" />
    </form>
</body>


C#
protected void Button1_Click(object sender, EventArgs e)
{  
    //Note: Use try catch block in as Session["Values"] will throw a null error for a user's first button click.
    try
    {
        Session["Values"] = ((string)Session["Values"]) + NewValueBox.Text + "<br />";
    }
    catch
    {
        Session["Values"] = NewValueBox.Text + "<br />";
    }
    try
    {
        ValuesDiv.InnerHtml = ((string)Session["Values"]);
        NewValueBox.Text = "";
    }
    catch
    {
    }
}
 
Share this answer
 
v2
Comments
Sandeep Mewara 21-Feb-11 8:38am    
Surely Session can be one of the ways but why to use it if it can be avoided.
Have a look at my answer at the earlier question: http://www.codeproject.com/Questions/160200/values-entered-in-the-textbox-should-b-displayed-d.aspx
You can try the concept:
Tokenizing Autocomplete Text Entry
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900