ASP.NET WebFrom Component LinkButton Programming

xiaoxiao2021-03-06  121

Author: Runner from: yesky

The LinkButton component in the ASP.NET's WebForm component is also a server-side component, which is a bit similar to the identifier in the HTML. Its main role is to display a hyperlink in the ASP.NET page. When this link is pressed, the page will pass the information to the server side, and the corresponding event is processed on the server. One. Important composition of the LinkButton component: We explain some common properties, events of the LinkButton component, through the table below.

The common properties of the LinkButton component, the meaning of the event represents text This is a property, which is the text commandName displayed by the LinkButton component. The two properties of Commandargument are basically the same. When the Click event is triggered, it is convenient to pass this two attributes. The server is transmitted to the server. For some of these two properties, some important usages are summarized below. OnClick event is an event when the component is triggered when the component is Click, and is similar to the onClick event above, the difference is that this event is triggered, and the server is passed to the server side, the Commandargument property value.

two. Use the commandName property and the CommandArgument property in the ASP.NET page:

You may have a bit confused in the linkbutton component and the Commandargument property, what will they do. In fact, they have a very important role. For example, as follows:

If there is 100 LinkButton in one of your pages, then it is necessary to determine which linkbutton is pressed. If there is no two properties, you can assign a value by giving each linkButton's text attribute, and then determine which linkbutton is pressed by detecting the text attribute value. Of course, you can also give each LinkButton life different name (of course you are the same name, in the ASP.NET), then in the event handler, by detecting the sender attribute value to determine which linkbutton Pressed. Although these methods are feasible, they are not cumbersome. With the commandName property and the Commandargument property, you can easily solve these problems. Assign the linkButton's commandName property and the Commandargument property to the Commandargument property in the program, and then you can get the data in the COMMANDEventArgs class, so that which linkbutton is pressed until the determination is. So what is the COMMANDEVENTARGS class? The CommandEventArgs class stores the data related to the Button event, and can access these data through the properties of the CommandEventArgs class in the event processing. It is said that when LinkButton is pressed, the data triggered by this LinkButton is stored in the server's CommandEventArgs class, and the properties in the CommandEventArgs class have also accessed the posed LinkButton. In this way, maybe you still have a bit unclear, and below is specifically explained by a program example.

three. Specific use of the LinkButton component:

This article describes how the LinkButton component is described. How the LinkButton component passes the commandName attribute value and the Commandargument property value via an oncommand () event. And how to read the data in the CommandEventArgs class in the program. The LINK.ASPX source code code is as follows:

<% @ Page language = "c #" debug = "true"%> link button component presentation </ title> <script runat = "server"> protected void linkbutton_command (Object Sender, CommandeventArgs e) {Message. Text = "You choose:" E. comMandargument;} </ script> </ head> <body> <form runat = "server"> <Table Cellspacing = 0 cellpadding = 0 border = 1 > <Tr> <td> Please select Date: <TD> </ TR> <TR> <TD Align = Center> <ask: linkButton text = "Monday" runat = "server" commandargument = "Monday" oncommand = "LinkButton_Command" /> </ td> </ tr> <TD align = center> <ask: linkbutton text = "Tuesday" runat = "server" commandARGUMENT = "Tuesday" oncommand = "linkbutton_command" /> < / TD> </ tr> <tr> <td align = center> <ask: linkbutton text = "Wednesday" runat = "server" commandARGUMENT = "Wednesday" oncommand = "linkbutton_command" /> </ td> </ tr> <TR> <TD align = center> <ask: linkbutton text = "Thursday" runat = "server" Commandargument = "Thursday" oncommand = "LinkButton_Command" /> </ td> </ tr> <TR></p> <p><TD align = center> <ask: linkbutton text = "Friday" runat = "server" Commandargument = "Friday" oncommand = "LinkButton_Command" /> <TD> </ tr> <tr> <td align = center> < ASP: LinkButton Text = "Saturday" runat = "Server" Commandargument = "Saturday" oncommand = "LinkButton_Command" /> <TD> </ TR> <Tr> <TD align = center> <ask: linkbutton text = Sunday "runat =" server "commandARGUMENT =" Sunday "oncommand =" linkbutton_command "/> </ td> </ tr> </ table> <ask: label id =" message "runat =" server "/> </ form> </ Body> </ html> four. to sum up:</p> <p>This article describes some of the important constituents of the LinkButton component, namely important attributes and events. And through a program example to specifically explain his method of use. The emergence of the LinkButton component makes it increasingly convenient to pass the parameters in the ASP.NET page. But this component has a shortcoming, which is not to be used on a browser that does not support JavaScript language because he uses the Submit () method in the JavaScript language to submit the page.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-98934.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="98934" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.032</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'VsVuU62BItBG8RHFRUfe51yb4coXxU7tpUzslEpet8a8FkmOgcAmC4i6TwvAgQowt_2FLqaVdxoNibNzXa77MJYg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>