473,840 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:PlaceHolde r ID="placek" runat="server" />
</table>

In cs:
*/
protected void Page_Load(objec t sender, EventArgs e)
{
if (!Page.IsPostBa ck)
DisplayButtons( )
}

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

XmlDocument dom = new XmlDocument();
dom.LoadXml(Fil e.ReadAllText(S erver.MapPath(" Files") + "\\" +
"File.xml") );
XmlNode files = dom.SelectSingl eNode("files");

if (files != null && bDelete)
{
files.RemoveChi ld(files.ChildN odes[index - 1]);
File.WriteAllTe xt(Server.MapPa th("Files") + "\\" + "File.xml",
dom.InnerXml);
}
DisplayBanners( );
}

protected void PlacekAdd(objec t sender, EventArgs e)
{
XmlDocument dom = new XmlDocument();
dom.LoadXml(Fil e.ReadAllText(S erver.MapPath(" Files") + "\\" + "File.xml") );
fuNewBanner.Sav eAs(Server.MapP ath("Files") + "\\" +
"NewGeneratedFi leName");

XmlNode files = dom.SelectSingl eNode("files");
XmlDocumentFrag ment addxml = dom.CreateDocum entFragment();
addxml.InnerXml = "<file show=\"0\" path=\"Files/" + "NewGeneratedFi leName"
+ "\" href=\"" + "link from the textbox" + "\" type=\"picture\ " />";
files.InsertAft er(addxml, files.LastChild );
}
File.WriteAllTe xt(Server.MapPa th("Files") + "\\" + "File.xml",
dom.InnerXml);

DisplayButtons( );
}

protected void DisplayButtons( )
{
XmlDocument dom = new XmlDocument();
dom.LoadXml(Fil e.ReadAllText(S erver.MapPath(" Files") + "\\" + "File.xml") );
XmlNode files = dom.SelectSingl eNode("files");

placek.Controls .Clear();
int i=0;
foreach (XmlNode file in files)
{
i++;
Button btnDelete = new Button();
btnDelete.Comma ndArgument = i.ToString();
EventHandler eh = new EventHandler(Pl acekDelete);
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 2038
Hi again,
I can make Response.Redire ct 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.co m.plwrote in message
news:en******** **@node4.news.a tman.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:PlaceHolde r ID="placek" runat="server" />
</table>

In cs:
*/
protected void Page_Load(objec t sender, EventArgs e)
{
if (!Page.IsPostBa ck)
DisplayButtons( )
}

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

XmlDocument dom = new XmlDocument();
dom.LoadXml(Fil e.ReadAllText(S erver.MapPath(" Files") + "\\" +
"File.xml") );
XmlNode files = dom.SelectSingl eNode("files");

if (files != null && bDelete)
{
files.RemoveChi ld(files.ChildN odes[index - 1]);
File.WriteAllTe xt(Server.MapPa th("Files") + "\\" + "File.xml",
dom.InnerXml);
}
DisplayBanners( );
}

protected void PlacekAdd(objec t sender, EventArgs e)
{
XmlDocument dom = new XmlDocument();
dom.LoadXml(Fil e.ReadAllText(S erver.MapPath(" Files") + "\\" +
"File.xml") );
fuNewBanner.Sav eAs(Server.MapP ath("Files") + "\\" +
"NewGeneratedFi leName");

XmlNode files = dom.SelectSingl eNode("files");
XmlDocumentFrag ment addxml = dom.CreateDocum entFragment();
addxml.InnerXml = "<file show=\"0\" path=\"Files/" +
"NewGeneratedFi leName" + "\" href=\"" + "link from the textbox" + "\"
type=\"picture\ " />";
files.InsertAft er(addxml, files.LastChild );
}
File.WriteAllTe xt(Server.MapPa th("Files") + "\\" + "File.xml",
dom.InnerXml);

DisplayButtons( );
}

protected void DisplayButtons( )
{
XmlDocument dom = new XmlDocument();
dom.LoadXml(Fil e.ReadAllText(S erver.MapPath(" Files") + "\\" +
"File.xml") );
XmlNode files = dom.SelectSingl eNode("files");

placek.Controls .Clear();
int i=0;
foreach (XmlNode file in files)
{
i++;
Button btnDelete = new Button();
btnDelete.Comma ndArgument = i.ToString();
EventHandler eh = new EventHandler(Pl acekDelete);
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
2566
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 know exactly where the table will be located on the page until runtime. Before the form control table is added to the Placeholder, I'm adding a whole bunch of tables to the Placeholder. This is a flowchart program and I have multiple action boxes...
1
5379
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 question is when the button is clicked and a postback is performed, the controls that were in the placeholder no longer appears on the screen! Am I doing something wrong here? Why are the controls back on the screen eventhough they have enable view...
9
2456
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"); ucline.Initializecontrol(line,alternate); Placeholder1.Controls.Add(ucline); }
1
5698
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 the value of what the user selected but the PlaceHolder's Controls collection is empty. I've tried turning viewstate of the PlaceHolder on and off but it doesn't make a difference (and I think I should be able to leave it off). What could be...
0
1014
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 On the calling page I have: Protected WithEvents PH As System.Web.UI.WebControls.PlaceHolder Protected WithEvents phMain As System.Web.UI.WebControls.PlaceHolder
3
1818
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 with Pl3.ascx. Each .ascx file has controls that can fire som events(button, dropList...). When I start the page, B1 is default and every control on Pl1.ascx work very fine. When I choose B2 or B3 the .ascx file is loaded in the placeholder but no...
2
3497
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 control disappears from the placeholder. Am I missing something here Please help
0
1557
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, SelectEventArgs e); public event SelectHandler OnSelect; protected void Page_Load(object sender, EventArgs e)
2
1453
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 controls that are inside the second UserControl doesn't work the first time I try to rise them?
0
10916
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10657
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10299
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9436
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7836
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5684
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4071
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.