locked
call a method from another web page - asp.net c# RRS feed

  • Question

  • User-895033789 posted

    hi everybody

    i have 2 web pages, page1and page2(page1's popup)

    first i open page2 from page1 

    when i finish with page2 i will click page2's button1.

    I want button1 will call a method from page1 and close page2

    i tried:

    page1

     public void methodA()

    { some code

    }

    -------------------------

    page2 

    protected void button1_Click(object sender, EventArgs e)

    {

    namespace.page1 obj1 = new namespace();

    obj1.methodA();

     Response.Write("<script>window.close();</script>");

    }

    build succeeded but when i click button1 had an errors:

    Object reference not set to an instance of an object.

    How can i do that?

    Help me plz! 

    Sunday, March 4, 2012 10:22 AM

Answers

  • User629308654 posted

    In Web You can't do this way.(Looks you are windows app developer)

    Reason is your page 1 already render and responed to your browser when you click page 2 button. only way when Page 2 button click through javascript, you can refresh you page1.

    1) Keep some hidden field(s) in page 1

    2) update those hidden when page 2 button clicked using javascript

    Ex : window.opener.document.getElementById(Client ID of Hidden Field).value = value;

    3) refresh your page 1 using javascript.

    Ex : window.opener.location = window.opener.location;

    4) validate those hidden field on page load of page1

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 4, 2012 10:36 AM

All replies

  • User629308654 posted

    In Web You can't do this way.(Looks you are windows app developer)

    Reason is your page 1 already render and responed to your browser when you click page 2 button. only way when Page 2 button click through javascript, you can refresh you page1.

    1) Keep some hidden field(s) in page 1

    2) update those hidden when page 2 button clicked using javascript

    Ex : window.opener.document.getElementById(Client ID of Hidden Field).value = value;

    3) refresh your page 1 using javascript.

    Ex : window.opener.location = window.opener.location;

    4) validate those hidden field on page load of page1

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 4, 2012 10:36 AM
  • User-895033789 posted

    thanks Wink

    Sunday, March 4, 2012 10:47 AM