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

Email link closes grid and forwards to aspx page

8 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 24 Jul 2012, 08:46 PM

I had this problem before and never got and answer to it when i submitted a help ticket and now I am back to it becuase I have another case where I need to impliment it in a radgrid and cannot go back to a asp grid.  What is happening is that I need a link button or hyperlink button on a radgrid that when they click on it it opens in a new window a page to email personnel.  problem is when I do this it forwards the page to the email name or site in this case, need it to stay at grid and open a the email page and pass a variable to it.

   <telerik:GridTemplateColumn HeaderText="MAC #">
                                            <ItemTemplate>
                                                <asp:LinkButton ID="lnkEmail" runat="server" CommandName="Email" CommandArgument='<% #Bind("intUserId") %>' text='<% #Bind("strMacNum") %>'
                                                ToolTip="Email the IMO"></asp:LinkButton>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>


Right now its redirecting but i cannot have this, just needs to open the email page in another window while staying on grid page.

 If (e.CommandName = "Email") Then
            Dim RecordId As Integer = e.CommandArgument

            Response.Redirect("Email.aspx?Email=" & RecordId)

        End If

also tried this but no go, forwards the grid to email page.
 ClientScript.RegisterStartupScript(Me.GetType(), "OpenWin", "<script>openNewWin('" & url & "')</script>")

8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Jul 2012, 05:32 AM
Hi Kevin,

Another approach is to access the LinkButton in the ItemDataBound event and attaching an 'OnClick' event to open the RadWindow.

VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then
        Dim ditem As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim lnk As LinkButton = DirectCast(ditem.FindControl("lnkEmail"), LinkButton)
        Dim RecordId As Integer = Convert.ToInt16(lnk.CommandArgument)
        lnk.Attributes.Add("onclick", "OnClick('" + RecordId + "');return false;")
    End If
End Sub

Javascript:
<script type="text/javascript">
    function OnClick(RecordID)
    {
        var oWnd = radopen("Email.aspx?Email=" + RecordID, null);
        oWnd.center();
    }
</script>

Thanks,
Shinu.
0
Kevin
Top achievements
Rank 1
answered on 25 Jul 2012, 12:33 PM
Hi Shinu,
Thanks for the response, i am getting the following error on code behind for line 264

Input string was not in a correct format. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  
Exception Details: System.FormatException: Input string was not in a correct format.
  
Source Error: 
  
  
Line 262:            Dim Email As LinkButton = DirectCast(ditem.FindControl("lnkEmail"), LinkButton)
Line 263:            Dim recordId As Integer = Convert.ToInt32(Email.CommandArgument)
Line 264:            Email.Attributes.Add("onclick", "OnClick('" + recordId + "');return false;")
Line 265:
Line 266:            'If mac.Value = "2" And btelcom.Value = "False" Then
  
s for the response.  In my code behind I am getting the following error.

0
Jayesh Goyani
Top achievements
Rank 2
answered on 25 Jul 2012, 12:38 PM
Hello,

Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs)
        If TypeOf e.Item Is GridDataItem Then
            Dim ditem As GridDataItem = DirectCast(e.Item, GridDataItem)
            Dim lnk As LinkButton = DirectCast(ditem.FindControl("lnkEmail"), LinkButton)
                 lnk.Attributes.Add("onclick", "OnClick('" + Convert.ToString(lnk.CommandArgument) + "');return false;")
        End If
    End Sub


Thanks,
Jayesh Goyani
0
Kevin
Top achievements
Rank 1
answered on 25 Jul 2012, 12:56 PM
Hi,
Ok got past error by just makeing the integer a string, but now its run ita javscript error in that it says an object is expected.  its like its not finding the aspx page that I am calling.  I have it in my Admin folder under my directory which happens to be where the page is that a person is working on when they click the button,  i though it would find it but I get object expected error.

calls out this line
varoWnd = radopen("~/Admin/Email.aspx?Email=" + RecordID, null);
 even has as this
varoWnd = radopen("Email.aspx?Email=" + RecordID, null);
0
Jayesh Goyani
Top achievements
Rank 2
answered on 25 Jul 2012, 01:10 PM
Hello,

I think you are not able to get windowmanager in your JS function.

Please check examples in below links.
http://www.telerik.com/help/aspnet-ajax/window-programming-opening.html

Thanks,
Jayesh Goyani
0
Kevin
Top achievements
Rank 1
answered on 25 Jul 2012, 01:14 PM
Hi jayesh,

thanks for the help, so far i have gotten to this point, it is opening in window but I still get error of object doe snot support this property or method for this line.  Instead of radwin I am using the regular window.open which works but i would like in center of the page.

window.center();

 function OnClick(RecordID)
          {
              varoWnd = window.open("Email.aspx?Email=" + RecordID, null);
              window.center();
          }
0
Jayesh Goyani
Top achievements
Rank 2
answered on 25 Jul 2012, 01:26 PM
Hello,

Set popup in center position
http://stackoverflow.com/questions/4068373/center-a-popup-window-on-screen

Get browser window size
http://www.howtocreate.co.uk/tutorials/javascript/browserwindow


Not : window.center(); : it is the radwindow's method
and you are open simple window so it is gives error/not working.

If you want to open radwindow then please check below link.
http://www.telerik.com/help/aspnet-ajax/window-programming-opening.html

Thanks,
Jayesh Goyani
0
Kevin
Top achievements
Rank 1
answered on 25 Jul 2012, 01:48 PM
Hi,

Ok I got it working, using the radwindow, the problem now is that before my submit command or cancel command would close the window.  now they do not.  FYI i am using the aspx page in this rad window and they are link buttons, my send button still sends and email but it will not close the window.
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Kevin
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or