I used a asp:button to bind the data from a textbox into a grid, but my problem was getting the page to stop refreshing. So I changed the asp:button to html button, because it was server side causing the page to refresh. Now I dont know how to use the same c# code to bind the data using html button.
Here's an example of my c# code:
//Site Class
class Sites
{
//Strings and variables are created based off text box Id to make matter easier to read
public string SiteName { get; set; }
public string Slick { get; set; }
public string UserID { get; set; }
}
//Created a new list based on class.
//Items are added based on whats in the textboxes
//and events are fired to gridview by the click of the class button
protected void SiteDetails_Click(object sender, EventArgs e)
{
List<Sites> list;
if (Session["list"] == null)
{
list = new List<Sites>();
}
else
{
list = (List<Sites>)Session["list"];
}
list.Add(new Sites() { SiteName = Sname.Text, Slick = Slick.Text, UserID = User_ID.Text });
Session["list"] = list;
SiteGrid.DataSource = list;
SiteGrid.DataBind();
}
And This is my Html aspx page:
Site Details
SiteName:
<td style="width: 102px; height: 8px;">Slic:</td>
<td style="width: 153px; height: 8px;">
<asp:TextBox ID="Slick" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 129px; margin-left: 40px; height: 23px;">User ID:</td>
<td style="width: 152px; height: 23px;">
<asp:TextBox ID="User_ID" runat="server" style="font-weight: bold"></asp:TextBox>
</td>
<td style="width: 102px; height: 23px;">
Password:</td>
<td style="width: 153px; height: 23px;">
<asp:TextBox ID="Pass" runat="server" TextMode="Password" ></asp:TextBox>
</td>
</tr>
<%-- //Site Button--%>
<tr>
<td></td>
<td>
<button ID="SiteDetails" OnClick="SiteDetails_Click()">AddSites</button>
</td>
</tr>
</table>
<%-- //Site GridView--%>
<asp:GridView ID="SiteGrid" class="table-bordered table-hover tableGridLines="None">
</asp:GridView>