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

How to create a list of linkbuttons associate with one RadWindow and pass different value to the radwindow

4 Answers 80 Views
Window
This is a migrated thread and some comments may be shown as answers.
Tao
Top achievements
Rank 1
Tao asked on 01 Aug 2012, 04:02 AM
I try to open a RadWindow that will show different data by clicking a list of linkbuttons.  These linkbuttons should be created at runtime.
I made that work by the following code example
vb code
For
Each a In aList
 
                ' Dynamically create radWindows
                '************************************************************************
                Dim radWindow As New Telerik.Web.UI.RadWindow
                With radWindow
                    .ID = "radWindow" & a
                    .Modal = True
                    .NavigateUrl = "http://test.aspx?a=" & a
                End With
 
                ' Add new radWindow to radWindowManager
                Me.RadWindowManager1.Windows.Add(radWindow)
 
                ' Dynamically create linkbutton
                ' *************************************************************************
                Dim lbtnSchool As New LinkButton
                With lbtnSchool
                    .ID = "lbtn" & a
                    .OnClientClick = "openWindow('" & radWindow.ClientID & "');return false;"
                End With
                ' **************************************************************************
            Next

Javascript function
function
openWindow(id) {
       var win;
       win = $find(id);
       win.show();}

However, there is a problem. If I have 100 items to loop, there will be 100 RadWindows added to RadWindowManager. And this is not  acceptable. I want to use just one RadWindow and let all linkbuttons call this RadWindow, then pass different data to NavigateUrl . The question is how to pass data to just one RadWindow by different linkbutton?

It will be much easier If there is a server side method, like RadWindow.show() or.open(), which can allow me to open RadWindow in code behind. But seems like the only way to open the RadWindow is using javascript?

 

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Aug 2012, 06:17 AM
Hi Tao,

One suggestion is that you can attach the click event for each LinkButton and set corresponding NavigateUrl property of the RadWindow and open the RadWindow from serverside. Following is the sample code.

ASPX:
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
  <Windows>
    <telerik:RadWindow ID="RadWindow1" runat="server">
    </telerik:RadWindow>
  </Windows>
</telerik:RadWindowManager>
<asp:LinkButton ID="LinkButton1" runat="server" Text="LinkButton1" OnClick="LinkButton1_Click"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" Text="LinkButton2" OnClick="LinkButton2_Click"></asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" Text="LinkButton3" OnClick="LinkButton3_Click"></asp:LinkButton>

C#:
protected void LinkButton1_Click(object sender, EventArgs e)
 {
   RadWindow1.NavigateUrl = "~/Button/Button.aspx";
   string scriptstring = "<script language='javascript'>function f(){var oWnd = radopen('', 'RadWindow1');}; Sys.Application.add_load(f);</script>";
   Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", scriptstring);
 }
protected void LinkButton2_Click(object sender, EventArgs e)
 {
   RadWindow1.NavigateUrl = "~/RadTreeView/TargetURL.aspx";
   string scriptstring = "<script language='javascript'>function f(){var oWnd = radopen('', 'RadWindow1');}; Sys.Application.add_load(f);</script>";
   Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", scriptstring);
 }
protected void LinkButton3_Click(object sender, EventArgs e)
 {
   RadWindow1.NavigateUrl = "~/RadTreeView/dragndrop.aspx";
   string scriptstring = "<script language='javascript'>function f(){var oWnd = radopen('', 'RadWindow1');}; Sys.Application.add_load(f);</script>";
   Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", scriptstring);
 }

Hope this helps.

Regards,
Princy.
0
Tao
Top achievements
Rank 1
answered on 01 Aug 2012, 05:29 PM
Hi Princy,

Thank you for replying!
I tried your solution. But the difference is I'm trying to create linkbuttons at runtime. I'm looping through a list and the number of linkbutton is depended on how many items are in the list. So, I cannot preset linkbuttons on page. I tried following code, but it doesn't work. LinkButton_click function doesn't get called when click button.
For Each a In aList
                Dim lbtn As New LinkButton
                With lbtn
                    .ID = "lbtn" & a
                    ' attach click event
                    ' ****************************************
                   .OnClientClick = "LinkButton_Click"
                   ' I also tried to add attributes
                     ' .Attributes.Add("OnClick", "LinkButton_Click")
                    ' *****************************************
                  .CommandName = a
                End With
Next
 
   Protected Sub LinkButton_Click(sender As Object, e As System.EventArgs, c As CommandEventArgs)
 
            Dim bp As ATI.Galileo.ASPX.BasePage
            bp = CType(Me.Page, ATI.Galileo.ASPX.BasePage)
 
            RadWindow1.NavigateUrl = "a.aspx?name=" & a
 
            Dim scriptString As String = "<script language='javascript'>function f(){alert('sfsfsdf');var oWnd = radopen('', 'RadWindow1');}; Sys.Application.add_load(f);</script>"
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "radalert", scriptString)
        End Sub

0
Princy
Top achievements
Rank 2
answered on 02 Aug 2012, 04:31 AM
Hi Tao,

You can add click event Handler to the LinkButton as follows.

VB:
AddHandler lbtn.Click, AddressOf LinkButton_Click

Hope this helps.

Regards,
Princy.
0
Tao
Top achievements
Rank 1
answered on 02 Aug 2012, 09:02 PM
Hi Princy,

I think the problem is I put the code into page preRender. Because PreRender fires after loadViewState. Then The new link buttons are creating again after post back instead of using previouly created link buttons.  That's why it never goes into LinkButton_Click(). I believe it will work when I put the link button creation code into page Inti(). 
Tags
Window
Asked by
Tao
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Tao
Top achievements
Rank 1
Share this question
or