PlaceHolder + Events

A

AdamK.

/*
Hello,
Its maybe simple but i cant fix it :(

First i would say sry for my english, but i will try my best :)

Its web application and what i have in the files:

In aspx:
<table>
<asp:placeHolder ID="placek" runat="server" />
</table>

In cs:
*/
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
DisplayButtons()
}

protected void PlacekDelete(object sender, EventArgs e)
{
int index=0;
bool bDelete = int.TryParse(((Button)sender).CommandArgument,out index);

XmlDocument dom = new XmlDocument();
dom.LoadXml(File.ReadAllText(Server.MapPath("Files") + "\\" +
"File.xml"));
XmlNode files = dom.SelectSingleNode("files");

if (files != null && bDelete)
{
files.RemoveChild(files.ChildNodes[index - 1]);
File.WriteAllText(Server.MapPath("Files") + "\\" + "File.xml",
dom.InnerXml);
}
DisplayBanners();
}

protected void PlacekAdd(object sender, EventArgs e)
{
XmlDocument dom = new XmlDocument();
dom.LoadXml(File.ReadAllText(Server.MapPath("Files") + "\\" + "File.xml"));
fuNewBanner.SaveAs(Server.MapPath("Files") + "\\" +
"NewGeneratedFileName");

XmlNode files = dom.SelectSingleNode("files");
XmlDocumentFragment addxml = dom.CreateDocumentFragment();
addxml.InnerXml = "<file show=\"0\" path=\"Files/" + "NewGeneratedFileName"
+ "\" href=\"" + "link from the textbox" + "\" type=\"picture\" />";
files.InsertAfter(addxml, files.LastChild);
}
File.WriteAllText(Server.MapPath("Files") + "\\" + "File.xml",
dom.InnerXml);

DisplayButtons();
}

protected void DisplayButtons()
{
XmlDocument dom = new XmlDocument();
dom.LoadXml(File.ReadAllText(Server.MapPath("Files") + "\\" + "File.xml"));
XmlNode files = dom.SelectSingleNode("files");

placek.Controls.Clear();
int i=0;
foreach (XmlNode file in files)
{
i++;
Button btnDelete = new Button();
btnDelete.CommandArgument = i.ToString();
EventHandler eh = new EventHandler(PlacekDelete);
btnDelete.Click += eh;
btnDelete.Text="Delete";
TableRow tr = new TableRow();
TableCell td = new TableCell();
td.Controls.Add(btnDelete);
tr.Cells.Add(td);
placek.Controls.Add(tr);
}
}
/*

I dont have any posibility to check that sample, and i wrote this from my
memory.

I have a problem with working with that PlaceHolder, because on first
PageLoad everythinkg working.
When i click on delete, its working and delete one record, but when i add
new record, and after that i wanna try to delete i need to click twice in
the button to delete that record.

I dont know how to resolve that, and what i made wrong :(
Could u help me :)?

Adam
*/
 
A

AdamK.

Hi again,
I can make Response.Redirect for this page after do smt with the XML file,
but its not nice method, could u guys help me resolve problem with Events?

Adam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top