In the dialog box that you want to pop up from the asp.net webpage, some errors, warnings, and prompts are displayed. Currently, javascript is used for implementation. So when you call this dialog box, if you can dynamically change the small icon in the upper-left corner of the dialog box, you can give us some advice.
In addition, I have a page that I want to determine from which page the page jumps from. That is to say, Can I pass a parameter to the target page when I jump to the page to let the target page determine?
Some netizens replied:
// Dialog box
String str = "OK"; // you can set any variable or set a page number parameter.
String Error_Msg = "<script language = javascript> alert (" str "); </" "script>"; // This variable is uploaded to the javascript dialog box.
Response. Write (Error_Msg );
// Pass the value. General Practice
// If the original page is called old. aspx and there is a parameter oldID = 1, you can write it like this when you go to the new page:
Response. Redirect ("target. aspx? OldID = "Convert. ToInt32 (Request [" ID "])" ");
// If you want to return to the original old. aspx
// Write the new page in target. aspx.
Response. Redirect ("old. aspx? OldID = "Convert. ToInt32 (Request [" ID "])" ");
According to the above, the solution to the first problem is to splice the html string and then write it out. The second is to pass parameters through the url. I checked it.
I. Querystring
Querystring is a simple value transfer method. Its disadvantage is that it displays the value to be transferred in the address bar of the browser and cannot pass objects in this method. If you want to upload
It is best to use this method when delivering a security that is not so important or a simple value. The following is a small example to complete the data transfer process. The procedure is as follows:
1. Create a web form
2. Place a button1 in the new web form, and place two TextBox1 and TextBox2
3. Create a click event for the button
The Code is as follows:
Private void button#click
(Object sender, System. EventArgs e)
{
String url;
Url = "webform2.aspx? Name ="
TextBox1.Text "& email ="
TextBox2.Text;
Response. Redirect (url );
}
4. Create a new target page named webform2
5. Place Label1 and Label2 in webform2.
Add the following code to Page_Load of webform2:
Private void Page_Load
(Object sender, System. EventArgs e)
{
Label1.Text = Request. QueryString ["name"];
Label2.Text = Request. QueryString ["email"];
}
Run the command to view the passed result.
Ii. Use Session Variables
Using Session variables to pass values is the most common method. In this method, values can be transmitted not only to the next page, but also to multiple pages until the Session Variables
After the value is removed, the variable disappears. For example:
1. Create a web form
2. Place a button1 in the new web form, and place two TextBox1 and TextBox2
3. Create a click event for the button
The Code is as follows:
Private void button#click
(Object sender, System. EventArgs e)
{
Session ["name"] = TextBox1.Text;
Session ["email"] = TextBox2.Text;
Response. Redirect ("webform2.aspx ");
}
4. Create a new target page named webform2
5. Place Label1 and Label2 in webform2.
Add the following code to Page_Load of webform2:
Private void Page_Load
(Object sender, System. EventArgs e)
{
Label1.Text = Session ["name"]. ToString ();
Label2.Text = Session ["email"]. ToString ();
Session. Remove ("name ");
Session. Remove ("email ");
}
Run the command to view the passed result.
Iii. Use Server. Transfer
Although this method is a bit complicated, it is also a way to pass values on the page.
For example:
1. Create a web form
2. Place a button1 in the new web form, and place two TextBox1 and TextBox2
3. Create a click event for the button
The Code is as follows:
Private void button#click
(Object sender, System. EventArgs e)
{
Server. Transfer ("webform2.aspx ");
}
4. The TextBox1 is returned during the creation process. The value code of the TextBox2 control is as follows:
Public string Name
{
Get
{
Return TextBox1.Text;
}
}
Public string EMail
{
Get
{
Return TextBox2.Text;
}
}
5. Create a new target page named webform2
6. Place Label1 and Label2 in webform2.
Add the following code to Page_Load of webform2:
Private void Page_Load
(Object sender, System. EventArgs e)
{
// Create an instance of the original form
WebForm1 wf1;
// Obtain the instantiated handle
Wf1 = (WebForm1) Context. Handler;
Label1.Text = wf1.Name;
Label2.Text = wf1.EMail;
}