CodeAs follows:
1.Webform1.aspx
<% @ Page Language = "C #" codebehind = "webform1.aspx. cs" autoeventwireup = "false" inherits = "webapplication4.webform1" %>
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> webform1 </title>
<Meta name = "generator" content = "Microsoft Visual Studio. NET 7.1">
<Meta name = "code_language" content = "C #">
<Meta name = "vs_defaultclientscript" content = "JavaScript">
<Meta name = "vs_targetschema" content = "http://schemas.microsoft.com/intellisense/ie5">
<Script language = "JavaScript">
Function AA ()
{
// Document. All. label1.innerhtml = "OK ";
// Alert ("AA ");
Document. getelementbyid ('button2'). Click ();
}
</SCRIPT>
</Head>
<Body ms_positioning = "gridlayout">
<Form ID = "form1" method = "Post" runat = "server">
<Font face ="">
<Asp: Label id = "label1" style = "Z-INDEX: 101; left: 304px; position: absolute; top: 64px" runat = "server"> </ASP: Label>
<Asp: button id = "button1" style = "Z-INDEX: 102; left: 360px; position: absolute; top: 136px" runat = "server"
TEXT = "button1"> </ASP: button>
<Asp: button id = "button2" style = "Z-INDEX: 103; left: 320px; position: absolute; top: 208px" runat = "server"
TEXT = "button2"> </ASP: button> </font>
</Form>
</Body>
</Html>
2.Webform1.aspx. CS
InPage_load
Private VoidPage_load (ObjectSender, system. eventargs E)
{
If(! Ispostback)
{
This. Button1.attributes. Add ("onclick", "AA ()");
}
}
Add eventButton2
Private VoidButton2_click (ObjectSender, system. eventargs E)
{
This. Label1.text = "OK ";
}
Code is very simple
Running result
Click "Button1" Button , In Button2 Add a breakpoint to the event as follows:
YesButton2Event (it should be said thatLabel1The value is"OK")
But the result is
I don't know why label1 is empty. Can someone explain it ??
Source code: