| |

VerySource

 Forgot password?
 Register
Search
View: 1511|Reply: 15

js added content disappears after popup dialog

[Copy link]

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-2 09:00:01
| Show all posts |Read mode
I added a few lines with JS, there are html controls in the line, after filling in the content, I click submit, but when there is a background execution fails, the status value -1 is returned, I use the following code to process:
if (resultNum == -1) {
                strScript = "<script> alert ('Add failed!'); </ script>";
                Page.ClientScript.RegisterStartupScript (this.GetType (), "Prompt", strScript);
                return;
            }

After the "Add failed!" Prompt box appeared, I clicked OK to close the dialog box, but the content added by JS was gone, how can I keep the content added by JS from disappearing?
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-19 14:30:01
| Show all posts
Page.ClientScript.RegisterStartupScript (this.GetType (), "Prompt", strScript); Will there be any problems writing it like this
Reply

Use magic Report

0

Threads

17

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-3-19 17:15:01
| Show all posts
What exactly is the "html control" of the landlord?
It should be that when submitting, the value assigned by the front-end js is lost, and the back-end read is empty, causing the new city to fail!
Reply

Use magic Report

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 United States

Post time: 2020-3-19 23:00:02
| Show all posts
What was added before with JS?
Reply

Use magic Report

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 United States

Post time: 2020-3-20 10:30:01
| Show all posts
Why not:
Page.RegisterClientScriptBlock ("Hint", strScript);
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-3-20 14:00:02
| Show all posts
Added content is tdObj.innerHTML = "<input type = 'text' name = 'txtOptions _" + oldTrObj.childNodes (1) .innerText + "' style = 'width: 60%' runat = 'server' />&nbsp; Value: <input type = 'text' name = 'txtValue _ "+ oldTrObj.childNodes (1) .innerText +"' runat = 'server' maxlength = '3' TextInfo = 'point value' RuleText = 'regNumber' style = 'width : 50px '> ";

The reason for the failure is because of duplicate records or other reasons, but not because the value cannot be obtained.
Reply

Use magic Report

0

Threads

26

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2020-3-21 22:15:01
| Show all posts
If there is a script error, your pop-up dialog box may not be executed! You first check your script ~!
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-3-22 13:00:01
| Show all posts
There is no script error, nor does it mean that there is no pop-up dialog box. After the dialog box pops up, click OK.
Reply

Use magic Report

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-3-22 14:45:02
| Show all posts
Post your code and see
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-3-24 14:00:02
| Show all posts
Front page
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default.aspx.cs" Inherits = "Fun_Test_Default"%>

<! 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> Untitled page </ title>
    <script type = "text / javascript" src = "MyJs.js"> </ script>
</ head>
<body>
    <form id = "form1" runat = "server">
    <div>
    <table id = "Upload" width = "300px" cellspacing = "1">
        <tr>
            <td class = "left" width = "5%">
                </ td>
            <td class = "left" align = "center">
                Attachments </ td>
        </ tr>
        <tr>
            <td class = "left" width = "5%">
                <input name = "chkAttach" type = "checkbox" />
            </ td>
            <td class = "right">
                <input id = "File1" name = "UploadFiles" type = "file" style = "width: 90%" runat = "server" />
            </ td>
        </ tr>
    </ table>
    </ div>
    <div align = "right">
        <input type = "button" value = "Add attachment" onclick = "AddRow ()" />&nbsp;
        <input type = "button" value = "delete attachment" onclick = "DelRow ()" />&nbsp;
    </ div>
    <div>
    <asp: Button runat = "server" ID = "btnSave" Text = "Save" ToolTip = "Save" CssClass = "btnSave" OnClick = "btnSave_Click" />
    </ div>
    </ form>
</ body>
</ html>
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