| |

VerySource

 Forgot password?
 Register
Search
Author: kong8008

js added content disappears after popup dialog

[Copy link]

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-3-24 15:30:01
| Show all posts
Background page:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

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

    }

    protected void btnSave_Click (object sender, EventArgs e) {
        string strScript = "";
        int resultNum = -1;

        if (resultNum == -2) {
            strScript = "<script> alert ('This contact already exists!'); </ script>";
            Page.ClientScript.RegisterStartupScript (this.GetType (), "Prompt", strScript);
            return;
        } else if (resultNum == -1) {
            strScript = "<script> alert ('Add failed!'); </ script>";
            Page.ClientScript.RegisterStartupScript (this.GetType (), "Prompt", strScript);
            return;
        } else {
            strScript = "<script> alert ('Add successfully!');
            Page.ClientScript.RegisterStartupScript (this.GetType (), "Prompt", strScript);
        }
    }
}
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-3-24 16:30:02
| Show all posts
JS file code:
// JScript file

function AddRow ()
{
    var tableObj = document.getElementById ("Upload");
    var trObj = tableObj.insertRow ();

                        
    tdObj = trObj.insertCell ();
    tdObj.innerHTML = "<input name = 'chkAttach' type = 'checkbox' />";
    tdObj.width = "5%";
    tdObj.className = "left";
    
    tdObj = trObj.insertCell ();
    tdObj.innerHTML = "<input name = 'UploadFiles' type = 'file' style = 'width: 90%' runat = 'server' />";
    tdObj.className = "right";
}

// delete a line

function DelRow ()
{
    var tableObj = document.getElementById ("Upload");
    for (i = 1; i <tableObj.rows.length; i ++)
    {
        if (tableObj.rows [i] .cells [0] .firstChild.checked == true)
        {
            tableObj.deleteRow (i);
            i--;
        }
    }
}
Reply

Use magic Report

0

Threads

17

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-3-27 11:30:01
| Show all posts
The problem lies in the refresh. The landlord tries it. Click IE's "Refresh", and the content you added will be lost.
You can use Ajax to update records without refreshing the page. Returns the resultNum value and pops up a dialog with JS in the foreground.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-27 23:45:01
| Show all posts
You are performing a button click event and the page refreshes, so there is no more
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-28 11:45:02
| Show all posts
<atlas: ScriptManager EnablePartialRendering = "true" ID = "scriptman1" runat = "server" />
.
.
.
.
<atlas: UpdatePanel ID = "updatetxjnh" runat = "server">
<ContentTemplate>
<asp: Button runat = "server" ID = "btnSave" Text = "Save" ToolTip = "Save" CssClass = "btnSave" OnClick = "btnSave_Click" />
</ ContentTemplate>
</ atlas: UpdatePanel>
Reply

Use magic Report

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-4-3 19:30:01
| Show all posts
Let me talk about your problem first, the following three buttons in your code:
<input type = "button" value = "Add attachment" onclick = "AddRow ()" />&nbsp;
<input type = "button" value = "delete attachment" onclick = "DelRow ()" />&nbsp;
<asp: Button runat = "server" ID = "btnSave" Text = "Save" ToolTip = "Save" CssClass = "btnSave" OnClick = "btnSave_Click" />

You click "Add attachment", execute AddRow () function of JS, add two controls,
Then click "Save" to submit the page. At this time, the page is executed from the beginning after the background execution is completed. It will not automatically click "Add Attachment" again. Of course, the previously added controls are gone. If you want to retain these controls and their values, you cannot. Submit page

Also in your JS code:
"<input name = 'UploadFiles' type = 'file' style = 'width: 90%' runat = 'server' />";
Runat = 'server' in this sentence has no effect, this new control will not be treated as a server control.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list