This is a migrated thread and some comments may be shown as answers.

RadListView and PostBack

1 Answer 163 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Fabio Cirillo
Top achievements
Rank 1
Fabio Cirillo asked on 05 Dec 2012, 04:07 PM
Hi,
i would that when i push the radbutton into radlistview, the postback must not start.

I load a list of generic in radlistview datasource from page_load with this code:

Private Sub Carica_risultati(ByVal _str1 As String, ByVal _str2 As String)
    Dim lista As List(Of PropertyUtente) = Loadsearch.Search(_str1, _str2)
    RadListView1.DataSource = lista
    RadListView1.DataBind()
End Sub
 
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim _str1, _str2 As String
    _str1 = Request.QueryString("_str1")
    _str2 = Request.QueryString("_str2")
    Carica_risultati(_str1, _str2)
    Me.ClientScript.RegisterStartupScript(Me.GetType, "", "Height_Div();", True)
End Sub

so i would that when start this code:
Protected Sub RadButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim Button As RadButton = CType(sender, RadButton)
    Dim item As RadListViewDataItem = CType(Button.Parent, RadListViewDataItem)
    Response.Redirect("Card.aspx?_id=" & item.GetDataKeyValue("idutente"))
End Sub

I do not want to run the code again in page_load, Is possible?

Under there is asp code too

<telerik:RadListView ID="RadListView1" runat="server"  DataKeyNames="idutente"
                   ItemPlaceholderID="Contenitore" AllowPaging="True" Skin="Simple">
                   <LayoutTemplate>
                       <fieldset id="FieldSet1">
                           <legend>Risultati della ricerca:</legend>
                           <asp:PlaceHolder ID="Contenitore" runat="server"></asp:PlaceHolder>
                           <div style="clear: both">
                           </div>
                           <div>
                               <div style="float: left; margin-left: 30%;">
                               <telerik:RadButton ID="btnFirst" runat="server" Text="Prima" CommandName="Page" CommandArgument="First"
                               Enabled="<%#Container.CurrentPageIndex > 0 %>" Skin="Sunset">
                               </telerik:RadButton>
                               <telerik:RadButton ID="btnPrev" runat="server" Text="Precedente" CommandName="Page" CommandArgument="Prev"
                               Enabled="<%#Container.CurrentPageIndex > 0 %>" Skin="Sunset">
                               </telerik:RadButton>
                                   <span style="vertical-align: top; position: relative; top: 4px">Pagina
                                       <%#Container.CurrentPageIndex + 1 %>
                                       di
                                       <%#Container.PageCount %></span>
                               <telerik:RadButton ID="btnNext" runat="server" Text="Successiva" CommandName="Page" CommandArgument="Next"
                               Enabled="<%#Container.CurrentPageIndex + 1 < Container.PageCount %>" Skin="Sunset">
                               </telerik:RadButton>
                               <telerik:RadButton ID="btnLast" runat="server" Text="Ultima" CommandName="Page" CommandArgument="Last"
                               Enabled="<%#Container.CurrentPageIndex + 1 < Container.PageCount %>" Skin="Sunset">
                               </telerik:RadButton>
                               </div>
                           </div>
                       </fieldset>
                   </LayoutTemplate>
                   <ItemTemplate>
                       <fieldset style="float: left; width: 494px; height: 180px">
                           <legend>Categoria:
                               <%# CType(Container.DataItem, PropertyUtente).Desccategoria%>
                           </legend>
                           <table cellpadding="0" cellspacing="0" width="95%">
                               <tr>
                                   <td style="width: 80%;">
                                       <table cellpadding="5" cellspacing="0">
                                           <tr>
                                               <td style="width: 20%;">
                                                   Nome:
                                               </td>
                                               <td style="width: 80%; text-align:left; color:#D5842B">
                                                   <%# CType(Container.DataItem, PropertyUtente).utente%>
                                               </td>
                                           </tr>
                                           <tr>
                                               <td style="width: 20%;">
                                                   Città:
                                               </td>
                                               <td style="width: 80%; text-align:left">
                                                   <%# CType(Container.DataItem, PropertyUtente).Desccomune%>
                                               </td>
                                           </tr>
                                           <tr>
                                               <td style="width: 20%;">
                                                   Telefono:
                                               </td>
                                               <td style="width: 80%; text-align:left">
                                                   <%# CType(Container.DataItem, PropertyUtente).Telefono%>
                                               </td>
                                           </tr>
                                           <tr>
                                               <td style="width: 20%;">
                                                   Cellulare:
                                               </td>
                                               <td style="width: 80%; text-align:left">
                                                   <%# CType(Container.DataItem, PropertyUtente).Cellulare%>
                                               </td>
                                           </tr>
                                           <tr>
                                               <td style="width: 20%;">
                                                   Email:
                                               </td>
                                               <td style="width: 80%; text-align:left">
                                                   <%# CType(Container.DataItem, PropertyUtente).Email%>
                                               </td>
                                           </tr>
                                           <tr>
                                               <td>
                                               </td>
                                               <td style="width: 100%; text-align:center">
                                                   <telerik:RadButton ID="RadButton1" runat="server" Text="Visualizza biglietto" Skin="Sunset"
                                                    OnClick="RadButton1_Click">
                                                   </telerik:RadButton>
                                               </td>
                                           </tr>
                                       </table>                                                   
                                   </td>
                                    <td style="vertical-align: top; text-align: right; width: 100px;">
                                       <asp:Image ID="Image1" runat="server" ImageUrl='<%# CType(Container.DataItem, PropertyUtente).imageprofile%>' Height="125px" Width="110px"/>
                                   </td>                            
                               </tr>
                           </table>
                       </fieldset>
                   </ItemTemplate>
               </telerik:RadListView>

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 11 Dec 2012, 05:54 AM
Hello,

There are couple of ways to achieve your goal:

  • You could either enclose the code from the Page_Load event in if(!PostBack) statement and thus the code will be executed only on initial page load but not on subsequent postbacks.
  • Another option is to set some Session variable in the Click event of the button and then check in the Page_Load event for its value. If the value for example is false you will execute the code, if it is true you will.

All the best,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ListView
Asked by
Fabio Cirillo
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or