Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the skills of ASP.NET

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "what are the ASP.NET skills", which is easy to understand and clear, hoping to help you solve your doubts. Let the editor lead you to study and learn this article "what are the ASP.NET skills?"

ASP.NET tip: how to use JavaScript to call server-side methods in asp.net AJAX?

This does not mean to call a simple PageMethod, because static methods cannot manipulate the controls of the current page, so the static PageMethod function is the same as ordinary WebService, more limited.

So, calling a normal server-side method is actually initiating an asynchronous callback. The easiest way to do this is through UpdatePanel.

First define a hidden LinkButton that invokes the action we want to perform in its handling event:

< asp:LinkButton ID="linkUpdatePosts" runat="server" style="display:'none';" OnClick ="linkUpdatePosts_Clicked" />

/ / Refresh the list of posts (for client js to call) protected void linkUpdatePosts_Clicked (object sender, EventArgs e) {LoadPosts ();}

Then a function can be defined in JavaScript to trigger the postback of the LinkButton:

/ / refresh the list of posts function refreshPosts () {_ _ doPostBack ('

< %= linkUpdatePosts.UniqueID %>

',');}

ASP.NET tip: how to get the value of a cell in GridView editing state?

Is this code still in use?

Var txtName = grid1.Rows [e.RowIndex] .cells [0] .FindControl ("txtName") as TextBox; if (txtName! = null) {/ / read value / /}

In fact, this work (finding the control in the cell and trying to get the value in it) has been encapsulated. Now, all you have to do is call the ExtractValuesFromCell method.

This method is also supported by many column types:

DataControlField, BoundField, AutoGeneratedField, CheckBoxField, ImageField, TemplateField, DynamicField

You can use it in GridView's RowUpdating, RowDeleting and other events. With this method, the value can be extracted into the desired dictionary and then read from the dictionary. These dictionaries include: e.Keys, e.NewValues, e.OldValues and so on.

A small piece of example code:

/ / Update protected void grid1_RowUpdating (object sender, GridViewUpdateEventArgs e) {var row = grid1.Rows [e.RowIndex]; / / extract the value of the Id field grid1.Columns [0] .ExtractValuesFromCell (e.Keys, row.Cells [0] as DataControlFieldCell, DataControlRowState.Edit, true / * include readonly * /) / / extract the value of Name field grid1.Columns [1] .ExtractValuesFromCell (e.NewValues, row.Cells [1] as DataControlFieldCell, DataControlRowState.Edit, true / * include readonly * /); var id = int.Parse (e.Keys ["id"]. ToString ()); var name = (string) ValuesFromCell ["name"] / / perform relevant database update operations / /}

In this way, we can use BoundField as much as possible in most situations, and we can also read its editing value correctly, saving a lot of code for customizing TemplateField.

The above is all the content of this article "what are the ASP.NET skills?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report