| |

VerySource

 Forgot password?
 Register
Search
View: 852|Reply: 7

Why does the ServerClick method of the System.Web.UI.HtmlControls.HtmlAnchor control execute twice? ?

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-11 09:40:01
| Show all posts |Read mode
protected System.Web.UI.HtmlControls.HtmlAnchor Aback;

...
this.Aback.ServerClick + = new System.EventHandler (this.Aback_ServerClick);
...

public void Aback_ServerClick (object sender, System.EventArgs e)
{
// The code at this location is executed twice
int lbid = Convert.ToInt32 (this.ListBox1.SelectedItem.Value.ToString ()); // Line 1
...
} // line 9

---------------------------------------
The above is the code in question

When I clicked the back button (Aback), I saw in the breakpoint that the code in the ServerClick method was executed twice. The first time, after the last sentence was executed to line 9}, it did not come out, but continued to Line 1.
Because the content of the line is a listbox, when the second execution reaches line 1, this will prompt me to set the object reference to the object instance.

Does anyone know why? Anxious to me.
please. Thank you, brothers and sisters.
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-15 14:18:01
| Show all posts
Is it executed once in Page_Load? You may not add IsPostBack to judge it.
Reply

Use magic Report

0

Threads

60

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-1-15 15:00:01
| Show all posts
The above code, I can't see the problem

Take a look here
private void InitializeComponent ()
{
this.Load + = new System.EventHandler (this.Page_Load);

}
#endregion


Does the following sentence have 2
this.Aback.ServerClick + = new System.EventHandler (this.Aback_ServerClick);
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-1-15 15:18:01
| Show all posts
this.Aback.ServerClick + = new System.EventHandler (this.Aback_ServerClick)
Did you write it manually?

Do you have another one in InitializeComponent?
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-15 18:09:02
| Show all posts
InitializeComponent
One of them is more likely.
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-15 20:09:01
| Show all posts
o01029
private void Page_Load (object sender, System.EventArgs e)
{
this.Strdbpath = Server.MapPath ("db01.mdb");
if (! IsPostBack) // Occurs when the page is first loaded
{
                                  Here is a lot of page initialization code. . . . .
}
}
Page_Load was not executed at the breakpoint. . .

3521565
this.Aback.ServerClick + = new System.EventHandler (this.Aback_ServerClick);
There is only one page search.

shenmue024
I found and posted here in the web form designer generated code.
private void InitializeComponent () Found in this method.
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-16 03:36:02
| Show all posts
Cai GG, helped me look at it.
Ha ha
It should be this.Aback.ServerClick + = new System.EventHandler (this.Aback_ServerClick) in InitializeComponent ();
deleted.
No more execution.
The next time you make this HtmlAnchor control, you have to obediently delete this delegate manually. Ha ha.

Thank you guys.
Reply

Use magic Report

0

Threads

60

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-1-19 12:36:02
| Show all posts
In fact, it is not necessary to use HtmlAnchor at all. A LINKBUTTON can completely achieve the effect you want, and the WEB control is more suitable for programming
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