| |

VerySource

 Forgot password?
 Register
Search
View: 1032|Reply: 9

ASP.NET return parameter problem

[Copy link]

2

Threads

5

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-11-10 09:00:01
| Show all posts |Read mode
VS wants to send parameters back to the foreground in the background.
    With the following sentences, a warning box can pop up at the front desk.
        Response.Write("<script language=javascript>");
        Response.Write("alert('1111');");
        Response.Write("</script>");
   But I add one sentence.
        Response.Write("<script language=javascript>");
        Response.Write("document.getElementById('Textl').value='99999';");
        Response.Write("alert('1111');");
        Response.Write("</script>");
   There is no response from the front desk.
   Experts please advise.
   My purpose is to execute some statements in the background, and send the results back to the foreground control. I could add SERVER to the control. I feel that the above statement should be more convenient to use, thank you.
Reply

Use magic Report

0

Threads

64

Posts

45.00

Credits

Newbie

Rank: 1

Credits
45.00

 China

Post time: 2020-11-10 09:15:01
| Show all posts
document.getElementById('Textl').value='99999'
There is an error in this sentence, text1 is not found, of course the value is wrong
Reply

Use magic Report

0

Threads

119

Posts

67.00

Credits

Newbie

Rank: 1

Credits
67.00

 China

Post time: 2020-11-10 09:30:01
| Show all posts
Use RegisterClientScriptBlock()
as follows:
<html>
  <head>
    <script language="C#" runat="server">

      public void Page_Load(Object sender, EventArgs e)
      {

        if (!this.IsClientScriptBlockRegistered("clientScript"))
        {
          // Form the script that is to be registered at client side.
          String scriptString = "<script language=JavaScript> function DoClick() {";
          scriptString += "myForm.show.value='Welcome to Microsoft .NET'}<";
          scriptString += "/";
          scriptString += "script>";
          this.RegisterClientScriptBlock("clientScript", scriptString);
        }
      }

     </script>
  </head>
  <body topmargin="20" leftmargin="10">
<form id="myForm" runat="server">
<input type="text" id="show" style="width=200"> <input type="button" value="ClickMe" onclick="DoClick()">
</form>
  </body>
</html>
Reply

Use magic Report

0

Threads

64

Posts

45.00

Credits

Newbie

Rank: 1

Credits
45.00

 China

Post time: 2020-11-10 11:00:01
| Show all posts
You can not use this method, use <%=Background public variable%> to assign a value to Text1
<input id="Text1" type="text" value="<%=Background public variables%>" />
Reply

Use magic Report

0

Threads

13

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 Unknown

Post time: 2020-11-10 12:00:01
| Show all posts
The problem is obvious. Any content sent by Response.Write is at the top of the html page, which is before the <html> tag. At this time, all other elements in your page have not been created yet, document.getElementById('Textl') You can't get anything at all, you should use the RegisterStartupScript method to register this script.

=======================
www.iceice930.com
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-11-10 12:15:01
| Show all posts
Try this sentence document.All('Textl').InnerText
Text1 is Div
Or document.All('Textl').Value
Text1 is the input text box
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-11-10 12:30:01
| Show all posts
Support upstairs!!!
Reply

Use magic Report

0

Threads

24

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2020-11-10 13:00:01
| Show all posts
iceice930


   The problem is obvious. Any content sent by Response.Write is at the top of the html page, which is before the <html> tag. At this time, all other elements in your page have not been created yet, document.getElementById('Textl') You can't get anything at all, you should use the RegisterStartupScript method to register this script.

=======================
www.iceice930.com
  

agree!
then:

If Text1 is a server-side textbox, try this:

Response.Write("<script language=javascript>");
        Response.Write("document.getElementById('<%=Textl.Client%>').innerText='99999';");
        Response.Write("alert('1111');");
        Response.Write("</script>");
Reply

Use magic Report

2

Threads

5

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-11-10 13:30:01
| Show all posts
According to the method of RegisterStartupScript, there is a time problem, and it seems that this problem cannot be solved.
  The registered script is executed together with the button event. I now want to execute some statements in the background before executing the script.
If executed together with the button event, you can also use this method
BUTTON.Attributes.Add

   What I want to do now is: upload a picture, save the picture in the background, and then return the address of the picture to the foreground control, with a time interval in between.

   In order to solve this time interval, the JAVASCRIPT event cannot be triggered by ASP.NET. I don't know if ASP.NET has any way to actively send parameters to the foreground control.

  Thank you for your advice.
Reply

Use magic Report

0

Threads

13

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-11-10 14:00:01
| Show all posts
It is estimated that text1 was not found
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