Update panel and triggers from the relay controller

Hi, I found a code similar to the following online. It seems like it’s really great to get a button funeral in the relay controller to start a full cycle back to the server.

<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <%=DateTime.Now.ToString() %> </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="HiddenButton" /> </Triggers> </asp:UpdatePanel> <!--Make a hidden button to treat as the postback trigger--> <asp:Button ID="HiddenButton" runat="server" Style="display: none" Text="HiddenButton" /> <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"> <ItemTemplate> <!--when cick the button1, it will fire the hiddenButton--> <asp:Button ID="Button1" Text="Trigger" CommandArgument='<%# Eval("Id") %>' OnClientClick="$get('HiddenButton').click();return false;" runat="server" /> </ItemTemplate> </asp:Repeater> 

It uses hiddenButton to achieve this by attaching the click event of the original button to this. However, my addition to this was setting the CommandArgument for the button. I will also need it to be installed for HiddenButton.

Does anyone know how to do this?

+6
source share
2 answers

First, I would like to explain Disadvantage using the Update Panel using the exact same example that you provided.

Below is the original code

enter image description here


Exit

enter image description here


To display a 22 character string, you can check how much data is received and sent to the server. Imagine the following

  • If you want to send each Database query using the Update Panel , and your GridView is in the Update Panel !!!!!!
  • Suppose you would use ViewState data for each request and GridView Inside the Update Panel .

Both of the above methods are the worst in my understanding.


Now I will describe you Page Methods

Method Page Above Update Panel

Page Methods enable ASP.NET AJAX pages to directly execute Page's Static Methods using JSON (JavaScript Object Notation) . Instead of sending back and then receiving HTML markup , to completely replace our UpdatePanel's contents , we can use the Web Method to request only the information of interest.

Code example

enter image description hereenter image description here


Exit

enter image description here

Hope this clearly explains the difference in usage.


Response to the original request

You need to register the ItemDataBound event below Repeater and use the code below for it.

Code for

 protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Button btn = (Button)e.Item.FindControl("Button1"); btn.OnClientClick = string.Format("SubmitButton('{0}');return false;" , HiddenButton.ClientID); } } 

Javascript

 <script type="text/javascript"> function SubmitButton(btn) { $("#" + btn).click(); } </script> 

//Alternative

 <script type="text/javascript"> function SubmitButton(btn) { document.getElementById(btn).click(); } </script> 

Link and Here

+12
source

The HiddenButton control is a server control, but you are trying to access it in jQuery using its ASP.Net ID,

 <asp:Button ID="Button1" Text="Trigger" CommandArgument='<%# Eval("Id") %>' OnClientClick="$get('**HiddenButton**').click();return false;" runat="server" /> 

A quick way to fix this is to make a separate function,

 <script type="text/javascript"> function SubmitButton(btn) { $get("#" . btn).click(); } </script> 

and change your button code to,

 <asp:Button ID="Button1" Text="Trigger" CommandArgument='<%# Eval("Id") %>' runat="server" /> 

In the code behind, in the ItemDataBound event of the repeater, find the button and HiddenControl and set the Button1 property OnClientClick,

 Button1.OnClientClick= string.Format("SubmitButton('{0}');return false;",HiddenButton.ClientID); 
0
source

Source: https://habr.com/ru/post/886193/


All Articles