0

I have a function onRowClick called RowClick and is working fine. I am trying to move it to a button and call the function from the code behind. For some reason is not triggering the function.. Anyone knows why and how I can fix this?

aspx.cs

  if (e.CommandName == "Addvoucher")
            {

               GridDataItem item = (GridDataItem)e.Item;

            var id = item.GetDataKeyValue("RowID");

            ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "RowClick("+id+");", true);

            }

aspx

  <script>
        var popUpObj;
        function RowClick(sender, eventArgs) {
            var filterId = eventArgs.getDataKeyValue('RowID');


            popUpObj = window.open("voucher.aspx?param=" + filterId + "",
             "ModalPopUp",
             "toolbar=no," +
             "scrollbars=no," +
             "location=no," +
             "statusbar=no," +
             "menubar=no," +
             "resizable=0," +
             "width=530," +
             "height=500," +
             "left = 450," +
             "top=130" 
            );
             popUpObj.focus();
             LoadModalDiv();


         }


     function LoadModalDiv()
     {
         var bcgDiv = document.getElementById("divBackground");
         bcgDiv.style.display="block";
     }

     function HideModalDiv() {
         var bcgDiv = document.getElementById("divBackground");
         bcgDiv.style.display = "none";
     }

     </script>

IN page voucher.aspx

 <script type = "text/javascript">

             function OnClose() {

                 if (window.opener != null && !window.opener.closed) {
                     window.opener.location.reload(); //refreshing parent when popup close
                     // window.opener.HideModalDiv();
                 }

                 //if (window.closed==true) window.open("~/routedoc.aspx");
             }
             window.onunload = OnClose;

    </script>
5
  • Change RegisterStartupScript to RegisterClientScriptBlock. Commented May 25, 2015 at 5:52
  • 1
    Check browser console to see if there is any error ? Commented May 25, 2015 at 5:55
  • Uncaught TypeError: Cannot read property 'getDataKeyValue' of undefined Commented May 25, 2015 at 6:03
  • This is because eventAgrs is undefined because you haven't passed these arguments to the function when you are calling it from code behind. Commented May 25, 2015 at 6:05
  • Now just pass id as parameter and receive it as a normal parameter and use it directly in your js function. Please see the answer. Commented May 25, 2015 at 6:12

4 Answers 4

1

Change your js function like this

function RowClick(filterId) {

popUpObj = window.open("voucher.aspx?param=" + filterId + "",
         "ModalPopUp",
         "toolbar=no," +
         "scrollbars=no," +
         "location=no," +
         "statusbar=no," +
         "menubar=no," +
         "resizable=0," +
         "width=530," +
         "height=500," +
         "left = 450," +
         "top=130" 
        );
         popUpObj.focus();
         LoadModalDiv();


     }

There is no need of this line now var filterId = eventArgs.getDataKeyValue('RowID'); Now you can directly use the parameter filterId in your js function.

Sign up to request clarification or add additional context in comments.

6 Comments

emm yeah now is working but when i press the Close(X) the window does not close
I have just included the function RowClick in my answer you need other two functions also which i haven't included other functions because other functions will remain same.
Yes i didnt change anything else except the change you have told me and now i have this problem. I have update my code on question have a look
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check xhr.spec.whatwg.org. browserLink:37 Setting 'XMLHttpRequest.withCredentials' for synchronous requests is deprecated.
As the error says that it is deprecated so i guess you can't do that you may be running latest version of browser. Check it on another browser.
|
1

Calling JavaScript function on code behind i.e. On Page_Load

ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:FUNCTIONNAME(); ", true);

If you have UpdatePanel there then try like this

ScriptManager.RegisterStartupScript(GetType(), "Javascript", "javascript:FUNCTIONNAME(); ", true);

3 Comments

Uncaught TypeError: Cannot read property 'getDataKeyValue' of undefined
getDataKeyValue ??. Post your code where u using getDataKeyValue ?
is the first line on script
0

Because you are calling RowClick() and in your code you are calling the second parameter eventArgs and actually it's an undefined value.

Make sure you pass the correct parameters.

Since you just calling a javscript function then I would recommend to just on the grid row data bound just assign the value to an anchor a tag or a button to just call the javascript.

3 Comments

Can i call the function from here? <telerik:GridButtonColumn Text="Add Voucher" UniqueName="Addvoucher" HeaderText="Addvoucher" CommandName="Addvoucher" > </telerik:GridButtonColumn>
No, just add a template column then add a link then on the grid row databound event find that link and update the href with javascript:RowClick(123) assuming 123 is ur id
I have try your way and i cant pass the RowID as parameter. Any idea why?
0

The problem is you are not passing any arguments for that js function from server side but you are getting data key value in client function as in your edited question pass row id from server side and change the client side function as below,

function RowClick(rowId)
{ 
  // use rowId
  popUpObj = window.open("voucher.aspx?param=" + rowId + "",
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.