Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8371629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:12:34+00:00 2026-06-09T14:12:34+00:00

I have now working updatable news using xml, but whenever i refresh the 1st

  • 0

I have now working updatable news using xml, but whenever i refresh the 1st Page which is the Inserting/Updating Page it’s still posting even if i emptied the textboxes.

Code of 1st HTML/ASPX File:

(

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

public partial class Main : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        XmlDocument xmlfile = new XmlDocument();
        xmlfile.Load(Server.MapPath("~/TestXML.xml"));
        //create element
        XmlElement theNewsTag = xmlfile.CreateElement("news");
        XmlElement theTitleTag = xmlfile.CreateElement("title");
        XmlElement theContentsTag = xmlfile.CreateElement("contents");
        //create text node
        XmlText theTitleText = xmlfile.CreateTextNode(xmlTitle.Text);
        XmlText theContentsText = xmlfile.CreateTextNode(xmlContent.Text);
        //append
        theTitleTag.AppendChild(theTitleText);
        theContentsTag.AppendChild(theContentsText);

        theNewsTag.AppendChild(theTitleTag);
        theNewsTag.AppendChild(theContentsTag);
        //save
        xmlfile.DocumentElement.AppendChild(theNewsTag);
        xmlfile.Save(Server.MapPath("~/TestXML.xml"));

        xmlTitle.Text = "";
        xmlContent.Text = "";

        Response.Redirect(Server.MapPath("~/Main.aspx"));
    }
}

My 1st HTML/ASPX File (For inserting/Updating)

<h2>Title</h2>
    <asp:TextBox ID="xmlTitle" runat="server"/>
<h2>Content</h2>
    <asp:TextBox ID="xmlContent" runat="server"/>
<h2>Insert XML</h2>
    <asp:Button ID="Button1" runat="server" Text="Post News" 
onclick="Button1_Click" />

My 2nd HTML/ASPX File (For Viewing the XML File)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="xmlpath.aspx.cs" Inherits="xmlpath" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ListView ID="ListView1" runat="server" DataSourceID="newDS">
            <LayoutTemplate>
                <div id="ItemPlaceHolderContainer"></div>
                <span id="ItemPlaceHolder" runat="server"></span>
            </LayoutTemplate>

            <ItemTemplate>
                <h2><%#XPath("title") %></h2>
                <p><%#XPath("contents") %></p>
            </ItemTemplate>
        </asp:ListView>
        <asp:XmlDataSource ID="newDS" runat="server" DataFile="~/TestXML.xml">
        </asp:XmlDataSource>
    </div>
    </form>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:12:36+00:00Added an answer on June 9, 2026 at 2:12 pm

    When you refresh your page it reposts the data, It also show you a dialog box
    Confirm Form Resubmission so actually you are pressing the button again.

    In your page load create this

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["Key"] = "1";
        }
    
    }
    

    and check the session before button click

    protected void button_Click(object sender, EventArgs e)
     {
        if (Session["Key"].ToString() == "1")
        {
               XmlDocument xmlfile = new XmlDocument();
        xmlfile.Load(Server.MapPath("~/TestXML.xml"));
        //create element
        XmlElement theNewsTag = xmlfile.CreateElement("news");
        XmlElement theTitleTag = xmlfile.CreateElement("title");
        XmlElement theContentsTag = xmlfile.CreateElement("contents");
        //create text node
        XmlText theTitleText = xmlfile.CreateTextNode(xmlTitle.Text);
        XmlText theContentsText = xmlfile.CreateTextNode(xmlContent.Text);
        //append
        theTitleTag.AppendChild(theTitleText);
        theContentsTag.AppendChild(theContentsText);
    
        theNewsTag.AppendChild(theTitleTag);
        theNewsTag.AppendChild(theContentsTag);
        //save
        xmlfile.DocumentElement.AppendChild(theNewsTag);
        xmlfile.Save(Server.MapPath("~/TestXML.xml"));
    
        xmlTitle.Text = "";
        xmlContent.Text = "";
    
        Response.Redirect(Server.MapPath("~/Main.aspx"));
        Session["Key"] = "0"; // set key = 0 
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on updating my page using javascript/jquery and have now run into
I have this regex working but now need to allow numbers without the decimal
I finally have this working now but would like to know how I can
Never Mind it's working now (have no idea why but that's ok), and thank
The first part is now working [ I have the following which just seems
I have been working now for few days on a small C program which
I have now been working as a web developer for two weeks and have
I just have learnt how cool RSpec and Cabybara is, and now working around
I have checked out now a local working copy of a codebase that lives
I am currently working on kerberos, and for now have this doubt on PAC

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.