views:

26

answers:

2

Hi guys,

I have this javascript

function myFunction(source) {
    window.open(source, "Title", 'width=400, height=400');
}

and in c# code I call it by

HtmlPage.Window.Invoke("myFunction", source);

which opens up a aspx page and goes to its OnLoad function:

protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);

My questions are

  • how do I pass in parameters to the event args in the aspx page? or is that even possible?
  • and how can I pass these parameters from my c# code to the javascript?

I am still learning javascript so please explain.

Thanks,

Voodoo

+2  A: 

You need to add a query string to the URL, such as http://server/path.file.aspx?SomeName=SomeValue.
You can access in in the C# server-side code by checking Request.QueryString["SomeValue"].

SLaks
+1  A: 

PageLoad happens on the serverside before the page has been sent down to the client's compter where the javascript is executed. Have a look at the asp.net page lifecycle It used to be one of our stock interview questions for web devs and it's amazing how many asp.net devs don't know it

SLaks answer is the easiest and most of the time will probably do you well, however you could always use an ajax operation to send some data back to the server and affect the page. This is more complicated but more powerful and leaves your URL looking nice and clean

Dylan