I have a textbox that the user suppose to place numbers on it,
and after he push the button, the number should pass to an array.
and each number and button pushed, should be saved in this array in order (for example : 3 , 4, 5, ….)
The problem is, that each time I push the button, then page_load occurs. I have this code :
protected string[] CurrentArr;
protected void Page_Load(object sender, EventArgs e)
{
if (CurrentArr != null)
{
CurrentArr = (string[])Session["CurrentArr"];
}
else
CurrentArr = new string[length];
which CurrentArr is the array that change over time.
I tried to solved it with AJAX as well :
<asp:ScriptManager runat="server" ID="sm">
</asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="update">
<ContentTemplate>
<input type="text" class="response" id="how_many" name="guess" placeholder="Enter your guess..." />
<asp:Button runat="server" class="button red" id="generate" name="generate" value="Generate!" OnClick="guess_Click" />
<asp:Button runat="server" class="button red" id="win" name="win" value="you won" />
</ContentTemplate>
</asp:UpdatePanel>
but it has no effect over my array (although my page doesnt post back…)
anyone has a solution ?
Thanks!
You are using an UpdatePanel, it is inherently AJAXified. Just add a trigger section to catch the button click:
The problem that you’re probably running into is that your array isn’t persisting through the postbacks. Try what you and ed were getting at, getting and setting from the session. I prefer not to use old school arrays. Consider a list, they are more versatile. And if you specifically need an array at the end then just use myList.ToArray();