views:

705

answers:

2

Hi All, Im executing javascript on a master page that is onClick event of a Menu item i set it to a hidden field and on Init of the Master page im not able to access this hidden field value.

Regards

+1  A: 

State isn't available in your controls until the Load phase. Before that you have to check in Request.Form

Joel Coehoorn
Hi,Thanks for your reply I checked with the Request.Form the count is Zero is there any other way to possibly get this value in the code behind ?
I also tried the same in the OnLoad and the Page_Load event still is always empty!
You need to post code then. What does your hidden field look like?
Bryan
A: 

Hi , This is the Code. In the Master Page i add the tag Then i have a script tag which runs a function setScript() that is everytime the Master Page is loaded setScript(); //I Navigate through all the menu items, which is navigate through all the "a" tags and then all of the a tags onclick event i add a new function ,below is the code

setScript();

    function setScript()
    {
        var objMenu=document.getElementById('<%=_menu.ClientID %>');
        var objHyperLinks=objMenu.getElementsByTagName('a');
        for(var i=0;i<objHyperLinks.length;i++)
        {
            var pageLoc=objHyperLinks[i].href;
            objHyperLinks.item(i).onclick=function (){return setEvent(this);};
        }
    }

    function setEvent(Loc)
    {
        var pageLoc=Loc+"";
        var iframePath=document.location.href;
        var targetPath=pageLoc;
        document.getElementById('<%=hdnPath.ClientID %>').value=targetPath;

        if(document.all)
        {
            document.all.frameLoader.src=targetPath;
        }
        else
        {
            var frame=window.frames;
            frame[0].location.href=targetPath;
        }
        return false;
    }

I alert the value of hdnPath right after the targetPath is assigned and i get to see the assigned value.