Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
538
Client CSOM setTargetURL changes text displayed, should only change url
posted

Hi, 

I am using webgrid 7.1 on .NET 1.1

 I have a webgrid with a column that is of type "HyperLink".

In that column i set the TargetURL to a javascript function using "java_script:OpenAudit(x)", this happens from code behind. Now the user click on a column to sort it. Sorting is done on clientside. After the sort, the TargetURL of each row is reset, and the hyperlink does not work anymore.

So i have added some client side code to the AuditGrid_AfterXmlHttpResponseProcessed event. In this code i set the targeturl back to the correct url using code below. After executing this code, the value of the cell becomes "java_script:OpenAudit(x)". The link works, both i don't want the URL to display in the cell, i want the value of the cell to be "Audit 2008/1" and the hypelink should be "java_script:OpenAudit(x)".  This looks like a bug in the CSOM. Does anybody know how to set the targetUrl from clientside code without messing up the value of the cell. I does work from codebehind, but i want to avoid postback ofcourse.

function AuditGrid_AfterXmlHttpResponseProcessed(gridName)

{

var grid = igtbl_getGridById(gridName);

if (grid!=null)

{

for(var rowcounter=0; rowcounter < grid.Rows.length; rowcounter++)

{

var row = grid.Rows.getRow(rowcounter);

if (row!=null)

{

var id

var idcell = row.getCellFromKey("Id");

if (idcell!=null)

var id = idcell.getValue();

 

var actioncodecell = row.getCellFromKey("ActionCode");

if (actioncodecell!=null)

{

var url = "java_script:OpenAudit('"+ id + "')";

actioncodecell.setTargetURL(url);

}

}

}

}

}

Remark:To test remove the _ from java_script!!!

Sorry for the bad formatting, both apparently the editor does a crappy job of copy-paste from visual studio 2003

Parents
No Data
Reply
  • 538
    posted

    Hi,

    For whomever is interested, the CSOM method setTargetURL is i.m.o incorrect. Below i have submitted the solution. i have implemented the function myself (as i do not want to change CSOM, otherwise upgrades would make the problem come back). I have included the part of the code that needs to be changed to make this work. I do not know this would work with "ordinary links" but for "script links" this works pretty good.

     if (actioncodecell!=null)

    {

     

    var el = actioncodecell.Element.firstChild;

    //following was hard to figure out!!!

     

    if (el!=null)

    el = el.firstChild;

     

    //set href

    el.href="java_script:OpenAudit('"+ id + "')";

     

    //set target

    el.target = "_self";

    }

     

Children