hi,
i m using the panel, in that panel when we click on 'new to do' it creates a new textbox and display it in the panel.. here is my code which i m using---->
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
using System.Drawing;
namespace TodoList
{
/// <summary>
/// Description for TodoList.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:TodoList runat=server></{0}:TodoList>"),
XmlRoot(Namespace = "TodoList")]
public class TodoList : Microsoft.SharePoint.WebPartPages.WebPart
{
static TextBox[] txt_arr = new TextBox[20];
public static int txt_count;
public TextBox tempBox,txtData;
public LinkButton NewTodo;
public LinkButton edit, save, add;
public Panel pnlMain,btnPanel,userPanel;
public GridView Grid;
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (txt_arr[0] is TextBox)
{
//for each button saved in our array, recreate it
foreach (TextBox txtbox in txt_arr)
{
add_txtbox(txtbox);
}
}
}
catch (Exception ex)
{
//lblStatus.Text += ex.Message.ToString();
}
}
protected override void OnPreRender(EventArgs e)
{
//Controls.Add(pnlMain);
try
{
if (txt_arr[0] is TextBox)
{
//for each button saved in our array, recreate it
foreach (TextBox txtbox in txt_arr)
{
add_txtbox(txtbox);
}
}
}
catch (Exception ex)
{
//lblStatus.Text += ex.Message.ToString();
}
base.OnPreRender(e);
}
protected override void CreateChildControls()
{
this.Controls.Clear();
//main panel properties
pnlMain = new Panel();
pnlMain.ID = "pnlMain";
Controls.Add(pnlMain);
pnlMain.Height = 100;
pnlMain.BackColor = Color.AliceBlue;
btnPanel = new Panel();
Controls.Add(btnPanel);
btnPanel.Visible = false;
btnPanel.BackColor = Color.Black;
// base.CreateChildControls();
userPanel = new Panel();
Controls.Add(userPanel);
userPanel.BackColor= System.Drawing.ColorTranslator.FromHtml("#5A8DC5");
add = new LinkButton();
add.Text = "[ADD]";
Controls.Add(add);
add.Click+=new EventHandler(add_Click);
btnPanel.Controls.Add(add);
save = new LinkButton();
save.Text = "[SAVE]";
Controls.Add(save);
save.Click+=new EventHandler(save_Click);
btnPanel.Controls.Add(save);
edit = new LinkButton();
edit.Text = "[EDIT]";
Controls.Add(edit);
edit.Click+=new EventHandler(edit_Click);
userPanel.Controls.Add(edit);
txtData = new TextBox();
Controls.Add(txtData);
//txtData.TextChanged+=new EventHandler(txtData_TextChanged);
btnPanel.Controls.Add(txtData);
//Link button propeties........
NewTodo = new LinkButton();
NewTodo.ID = "NewTodo";
NewTodo.Text = "[NewTodo]";
Controls.Add(NewTodo);
NewTodo.Click += new EventHandler(NewTodo_Click);
userPanel.Controls.Add(NewTodo);
base.CreateChildControls();;
}
protected void add_txtbox(TextBox txtBox)
{
try
{
//add to a container on the page
pnlMain.Controls.Add(txtBox);
//add a spacer after the control
pnlMain.Controls.Add(new LiteralControl("<br>"));
}
catch (Exception ex)
{
throw new Exception("can't create text box", ex);
}
}
public void save_function()
{
tempBox = txtData;
try
{
TextBox new_txtbox = new TextBox();
new_txtbox.ID = "" + (txt_count + 1);
txt_arr[txt_count++] = new_txtbox;
new_txtbox.Text = tempBox.Text;
add_txtbox(new_txtbox);
}
catch (Exception ex)
{
}
}
protected void NewTodo_Click(object sender, EventArgs e)
{
Controls.Add(btnPanel);
btnPanel.Visible = false;
save_function();
}
protected void edit_Click(object sender, EventArgs e)
{
//Controls.Add(btnPanel);
btnPanel.Visible = true;
}
protected void save_Click(object sender, EventArgs e)
{
//Controls.Add(btnPanel);
btnPanel.Visible = false;
save_function();
}
//protected void txtData_TextChanged(object sender, EventArgs e)
//{
// save_function();
//}
protected void add_Click(object sender, EventArgs e)
{
//Controls.Add(btnPanel);
btnPanel.Visible = true;
save_function();
//Controls.Add(btnPanel);
}
}
}
this is the code, it execute on server but does't execute well.. so pz check this code,it give some error then let me know... in this code in front of every textbox i need a delete button which deletes that textbox... i m trying with this for a long time, but not able to solve..
thanx in advance...