473,320 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

PlaceHolder + Events

/*
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
*/
Dec 28 '06 #1
1 2016
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
"AdamK." <ne***@azure.com.plwrote in message
news:en**********@node4.news.atman.pl...
/*
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
*/

Dec 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: blue | last post by:
I have a drop-down list, a radio button list and a submit button. I'm adding these controls to a table and I'm adding the table to a Placeholder. I'm adding it to the Placeholder because I don't...
1
by: Angel | last post by:
I have added controls to the placeholder control. All the controls that were added have EnableViewState = true including the placeholder. One of the controls has a button that performs a postback. My...
9
by: Anders K. Jacobsen [DK] | last post by:
Hi I have this that adds some usercontrol (UCTodays.ascx) to a placeholder foreach(A a in B){ UCTodays ucline = (UCTodays )LoadControl("UCTodays.ascx");...
1
by: Simon Wallis | last post by:
Hi, I have a PlaceHolder on a place, to which I add a DropDownList (using myPlaceHolder.Controls.Add(ddl). The user selects something from the DropDownList and posts the page. Now I try to get...
0
by: Chris Kettenbach | last post by:
How do I get the page to respond to events on a dynamically loaded user control in a placholder control? I am trying to reference the control in the placeholder from my codebehind for the page ...
3
by: PKin via DotNetMonster.com | last post by:
Hi, I have a web page with a radioButtonList with 3 buttons (B1,B2 and B3) and a placeholder. B1 will put an .ascx file (Pl1.ascx) in the placeHolder, B2 will do the same with Pl2.ascx and B3...
2
by: Vishal Gupta | last post by:
Hi all, I have a placeholder control on an ASPX page. I dynamically add a few button control and label control to the placeholder from code - all is well with the world. But on post back the...
0
by: seigo | last post by:
Hello, I faced with the following problem. I have a PlaceHolder on a page and a few UserControls which have custom events, for instance: public delegate void SelectHandler(object sender,...
2
by: David | last post by:
I have a UserControl loaded into a PlaceHolder and I have a button there which is suppose to load another UserControl into the same PlaceHolder and hide the previous one. Why does the events of the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.