Client ID returns null

Hi again,

Got stuck with a problem. I need to fetch the worksheet’s client id from the server.

Here are the following code. Before pasting the code I would like to explain the scenario. Here, using a Asp.Net TreeView to load the list of the worksheets so that users don’t have to scroll down to change the sheets. The NoScroll property is kept as true and the sheets are bigger enough.

foreach (WebWorksheet wrksht in grdWeb.WebWorksheets)
{
TreeNode twrksht = new TreeNode();
twrksht.Text = wrksht.Name;
string str_wrk = wrksht.ClientID;
str_wrk = wrksht.ID;
twrksht.NavigateUrl = “BLOCKED SCRIPTreturn getWorksheet(” + wrksht.ClientID + “)”;
tAssumption.ChildNodes.Add(twrksht);
}


The following codes are assigned in the client side.

function getWorksheet(wrkshid)
{
var elem = document.getElementById(wrkshid);
elem.click();
}

The problem is whenever I check the value for the worksheets ClientID using the quick watch during execution. I can see only null values. Is there any solution for this please?

Thanks & Regards

Prithiraj

Hi Prithiraj,

Please try the following code:

foreach (WebWorksheet wrksht in grdWeb.WebWorksheets)

{

TreeNode twrksht = new TreeNode();

twrksht.Text = wrksht.Name;

int index = wrksht.Index;

twrksht.NavigateUrl = "BLOCKED SCRIPTreturn getWorksheet(" + index + ")";

tAssumption.ChildNodes.Add(twrksht);

}

function getWorksheet(index)

{

var sheet = document.getElementById("grdWeb_TAB" + index);

if (sheet != null)

sheet.click();

}

The id of worksheet in page is combined with name of GridWeb, the constant string “_TAB” and the index of the worksheet. Please check the source of the page for reference.

Thank you.

Hi Thanks again,

The code doesn’t seem to work. It returns “The page cannot be found” error in the browser. What could be the reason and possible solution. The URL I get while clicking on the node is http://localhost/GridWebOnVS2005/group/BLOCKED SCRIPTreturn getWorksheet(1).

C#
twrksht.NavigateUrl = “BLOCKED SCRIPTreturn getWorksheet(” + index + “)”;

JavaScript
function getWorksheet(index)<o:p></o:p>

{

var sheet = document.getElementById(“grdWeb_TAB” + index);

if (sheet != null)

sheet.click();

}

I think, am missing something

One more thing, I need to ask, How can we freeze the header?

I look forward to your reply.

Thanks & Regards

Prithiraj Sengupta

Hi Prithiraj,

In fact “Java…ipt:” is changed to “BLOCKED SCRIPT…”, so I will attach here a screen shot of the line of code, please change your line of code according to the screen shot of the line of code, We have tested successfully with the TreeView control provided by VS.NET 2005.

Thank you.

Hi Amjad,

Thanks for the reply. The thing worked now in IE. Do you know anything equivalent to sheet.click() event for mozilla? It works in IE well, but doesnt work in mozilla. Browser sniffing is restricted in mozilla. One more thing I need to ask you… i.e I need to freeze the header of a web grid in Mozilla, it works fine with IE.

Regards
Prithiraj Sengupta

Hi,

Please try the following script for Mozilla and IE:

function getWorksheet(index)

{

var sheet = document.getElementById("grdWeb_TAB" + index);

if (sheet != null)

{

if (document.all) {

sheet.click(); //IE

}

else { // not IE

var e = document.createEvent('MouseEvents');

e.initEvent('click', true, true);

sheet.dispatchEvent(e);

}

}

}

To freeze header part:

grdWeb.WebWorksheets[0].FreezePanes(2, 0, 2, 0);

Thank you.