cause webpage one to reload when webpage two is closed.

Discussion in 'ASP .Net' started by Paul, Jun 17, 2008.

  1. Paul

    Paul Guest

    Hi I tried a google search but could not find anything. I am trying to cause
    one webpage to reload when a second web page is closed. The second webpage
    loads data into a session variable and when closed I need to reload the first
    page loading in the data from the session variable. Since I need to close
    the sescond form just setting the post back url to the first page on the
    close button from the second page is not quite what I am looking for.
    --
    Paul G
    Software engineer.
    Paul, Jun 17, 2008
    #1
    1. Advertising

  2. On Jun 17, 9:19 pm, Paul <> wrote:
    > Hi I tried a google search but could not find anything.  I am trying to cause
    > one webpage to reload when a second web page is closed.  The second webpage
    > loads data into a session variable and when closed I need to reload the first
    > page loading in the data from the session variable.  Since I need to close
    > the sescond form just setting the post back url to the first page on the
    > close button from the second page is not quite what I am looking for.
    > --
    > Paul G
    > Software engineer.


    Hi Paul,

    Try to add the following code to your second web page

    <body onunload="opener.location.href=opener.location.href;">

    You might be also interested to see the following thread
    http://forums.asp.net/t/988319.aspx

    Hope this helps
    Alexey Smirnov, Jun 17, 2008
    #2
    1. Advertising

  3. Paul

    Paul Guest

    Hi, thanks for the response.
    I tried adding
    <body onunload="opener.location.href=opener.location.href;"></body>
    to the source of the second page but get the error
    element body can not be nested within element td. I placed the code as
    follows in the second form aspx file.

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
    Runat="Server">

    <body onunload="opener.location.href=opener.location.href;"></body>


    followed by several html tables.
    Anyhow just wondering where to place the body tag?

    Also the way the user gets to the second page from the first page is just a
    hyperlink.
    thanks.

    --
    Paul G
    Software engineer.


    "Alexey Smirnov" wrote:

    > On Jun 17, 9:19 pm, Paul <> wrote:
    > > Hi I tried a google search but could not find anything. I am trying to cause
    > > one webpage to reload when a second web page is closed. The second webpage
    > > loads data into a session variable and when closed I need to reload the first
    > > page loading in the data from the session variable. Since I need to close
    > > the sescond form just setting the post back url to the first page on the
    > > close button from the second page is not quite what I am looking for.
    > > --
    > > Paul G
    > > Software engineer.

    >
    > Hi Paul,
    >
    > Try to add the following code to your second web page
    >
    > <body onunload="opener.location.href=opener.location.href;">
    >
    > You might be also interested to see the following thread
    > http://forums.asp.net/t/988319.aspx
    >
    > Hope this helps
    >
    Paul, Jun 17, 2008
    #3
  4. On Jun 17, 10:28 pm, Paul <> wrote:
    > Hi, thanks for the response.
    > I tried adding
    > <body onunload="opener.location.href=opener.location.href;"></body>
    > to the source of the second page but get the error
    > element body can not be nested within element td.  I placed the code as
    > follows in the second form aspx file.
    >
    > <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
    > Runat="Server">
    >
    >   <body onunload="opener.location.href=opener.location.href;"></body>
    >
    > followed by several html tables.
    > Anyhow just wondering where to place the body tag?
    >
    > Also the way the user gets to the second page from the first page is just a
    > hyperlink.
    > thanks.
    >
    > --
    > Paul G
    > Software engineer.
    >
    >
    >
    > "Alexey Smirnov" wrote:
    > > On Jun 17, 9:19 pm, Paul <> wrote:
    > > > Hi I tried a google search but could not find anything.  I am trying to cause
    > > > one webpage to reload when a second web page is closed.  The second webpage
    > > > loads data into a session variable and when closed I need to reload the first
    > > > page loading in the data from the session variable.  Since I need to close
    > > > the sescond form just setting the post back url to the first page on the
    > > > close button from the second page is not quite what I am looking for.
    > > > --
    > > > Paul G
    > > > Software engineer.

    >
    > > Hi Paul,

    >
    > > Try to add the following code to your second web page

    >
    > > <body onunload="opener.location.href=opener.location.href;">

    >
    > > You might be also interested to see the following thread
    > >http://forums.asp.net/t/988319.aspx

    >
    > > Hope this helps- Hide quoted text -

    >
    > - Show quoted text -


    The BODY element contains all the content of a document, including TD
    and TABLE. It can be nested within HTML element only. It seems that
    you are using Master page and it means you should change a BODY
    element of the Master page. If Master page is used for many Content
    pages then you can either make a copy of it (to apply changes to the
    BODY tag), or you can set your Master page body tag to:

    <body id="mBody" runat="server">

    Then add this on the page that has to be closed:

    public void Page_Load(Object sender, EventArgs e)
    {
    HtmlGenericControl body =
    (HtmlGenericControl)Master.FindControl("mBody");
    body.Attributes.Add("onunload",
    "opener.location.href=opener.location.href;");
    }

    I didn't test it, but I think it should work.
    Alexey Smirnov, Jun 17, 2008
    #4
  5. Paul

    Paul Guest

    Hi, I was able to add the body tag, since I am using a master page I had to
    create an id for the tag in the master page and set a public property, so
    thinking I can now run a script possibly to reload the first window.
    --
    Paul G
    Software engineer.


    "Alexey Smirnov" wrote:

    > On Jun 17, 9:19 pm, Paul <> wrote:
    > > Hi I tried a google search but could not find anything. I am trying to cause
    > > one webpage to reload when a second web page is closed. The second webpage
    > > loads data into a session variable and when closed I need to reload the first
    > > page loading in the data from the session variable. Since I need to close
    > > the sescond form just setting the post back url to the first page on the
    > > close button from the second page is not quite what I am looking for.
    > > --
    > > Paul G
    > > Software engineer.

    >
    > Hi Paul,
    >
    > Try to add the following code to your second web page
    >
    > <body onunload="opener.location.href=opener.location.href;">
    >
    > You might be also interested to see the following thread
    > http://forums.asp.net/t/988319.aspx
    >
    > Hope this helps
    >
    Paul, Jun 17, 2008
    #5
  6. Paul

    Paul Guest

    Hi, It works! I guess it must know what the parent window is to be able to
    reload it.
    Thanks!
    --
    Paul G
    Software engineer.


    "Alexey Smirnov" wrote:

    > On Jun 17, 10:28 pm, Paul <> wrote:
    > > Hi, thanks for the response.
    > > I tried adding
    > > <body onunload="opener.location.href=opener.location.href;"></body>
    > > to the source of the second page but get the error
    > > element body can not be nested within element td. I placed the code as
    > > follows in the second form aspx file.
    > >
    > > <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
    > > Runat="Server">
    > >
    > > <body onunload="opener.location.href=opener.location.href;"></body>
    > >
    > > followed by several html tables.
    > > Anyhow just wondering where to place the body tag?
    > >
    > > Also the way the user gets to the second page from the first page is just a
    > > hyperlink.
    > > thanks.
    > >
    > > --
    > > Paul G
    > > Software engineer.
    > >
    > >
    > >
    > > "Alexey Smirnov" wrote:
    > > > On Jun 17, 9:19 pm, Paul <> wrote:
    > > > > Hi I tried a google search but could not find anything. I am trying to cause
    > > > > one webpage to reload when a second web page is closed. The second webpage
    > > > > loads data into a session variable and when closed I need to reload the first
    > > > > page loading in the data from the session variable. Since I need to close
    > > > > the sescond form just setting the post back url to the first page on the
    > > > > close button from the second page is not quite what I am looking for.
    > > > > --
    > > > > Paul G
    > > > > Software engineer.

    > >
    > > > Hi Paul,

    > >
    > > > Try to add the following code to your second web page

    > >
    > > > <body onunload="opener.location.href=opener.location.href;">

    > >
    > > > You might be also interested to see the following thread
    > > >http://forums.asp.net/t/988319.aspx

    > >
    > > > Hope this helps- Hide quoted text -

    > >
    > > - Show quoted text -

    >
    > The BODY element contains all the content of a document, including TD
    > and TABLE. It can be nested within HTML element only. It seems that
    > you are using Master page and it means you should change a BODY
    > element of the Master page. If Master page is used for many Content
    > pages then you can either make a copy of it (to apply changes to the
    > BODY tag), or you can set your Master page body tag to:
    >
    > <body id="mBody" runat="server">
    >
    > Then add this on the page that has to be closed:
    >
    > public void Page_Load(Object sender, EventArgs e)
    > {
    > HtmlGenericControl body =
    > (HtmlGenericControl)Master.FindControl("mBody");
    > body.Attributes.Add("onunload",
    > "opener.location.href=opener.location.href;");
    > }
    >
    > I didn't test it, but I think it should work.
    >
    Paul, Jun 17, 2008
    #6
  7. On Jun 17, 11:25 pm, Paul <> wrote:
    > Hi, It works! I guess it must know what the parent window is to be able to
    > reload it.
    > Thanks!
    > --
    > Paul G
    > Software engineer.
    >
    >
    >
    > "Alexey Smirnov" wrote:
    > > On Jun 17, 10:28 pm, Paul <> wrote:
    > > > Hi, thanks for the response.
    > > > I tried adding
    > > > <body onunload="opener.location.href=opener.location.href;"></body>
    > > > to the source of the second page but get the error
    > > > element body can not be nested within element td.  I placed the code as
    > > > follows in the second form aspx file.

    >
    > > > <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
    > > > Runat="Server">

    >
    > > >   <body onunload="opener.location.href=opener.location.href;"></body>

    >
    > > > followed by several html tables.
    > > > Anyhow just wondering where to place the body tag?

    >
    > > > Also the way the user gets to the second page from the first page is just a
    > > > hyperlink.
    > > > thanks.

    >
    > > > --
    > > > Paul G
    > > > Software engineer.

    >
    > > > "Alexey Smirnov" wrote:
    > > > > On Jun 17, 9:19 pm, Paul <> wrote:
    > > > > > Hi I tried a google search but could not find anything.  I am trying to cause
    > > > > > one webpage to reload when a second web page is closed.  The second webpage
    > > > > > loads data into a session variable and when closed I need to reload the first
    > > > > > page loading in the data from the session variable.  Since I need to close
    > > > > > the sescond form just setting the post back url to the first page on the
    > > > > > close button from the second page is not quite what I am looking for.
    > > > > > --
    > > > > > Paul G
    > > > > > Software engineer.

    >
    > > > > Hi Paul,

    >
    > > > > Try to add the following code to your second web page

    >
    > > > > <body onunload="opener.location.href=opener.location.href;">

    >
    > > > > You might be also interested to see the following thread
    > > > >http://forums.asp.net/t/988319.aspx

    >
    > > > > Hope this helps- Hide quoted text -

    >
    > > > - Show quoted text -

    >
    > > The BODY element contains all the content of a document, including TD
    > > and TABLE. It can be nested within HTML element only. It seems that
    > > you are using Master page and it means you should change a BODY
    > > element of the Master page. If Master page is used for many Content
    > > pages then you can either make a copy of it (to apply changes to the
    > > BODY tag), or you can set your Master page body tag to:

    >
    > > <body id="mBody" runat="server">

    >
    > > Then add this on the page that has to be closed:

    >
    > > public void Page_Load(Object sender, EventArgs e)
    > > {
    > > HtmlGenericControl body =
    > > (HtmlGenericControl)Master.FindControl("mBody");
    > > body.Attributes.Add("onunload",
    > > "opener.location.href=opener.location.href;");
    > > }

    >
    > > I didn't test it, but I think it should work.- Hide quoted text -

    >
    > - Show quoted text -


    Great! :)
    Alexey Smirnov, Jun 17, 2008
    #7
  8. Paul

    Paul Guest

    Hi just had one last question. Not sure if there is anything that can be
    done about this but when webpage 2 reloads (I have some controls that
    postback) It also causes webpage 1 to reload. Is there anyway to have page
    one reload only when page two is closed? I guess the onunload event must
    occure when page 2 postsback to the server? Thanks.
    HtmlGenericControl body =

    (HtmlGenericControl)Master.FindControl("MasterPageBodyTag");
    body.Attributes.Add("onunload",
    "opener.location.href=opener.location.href;");
    --
    Paul G
    Software engineer.


    "Alexey Smirnov" wrote:

    > On Jun 17, 11:25 pm, Paul <> wrote:
    > > Hi, It works! I guess it must know what the parent window is to be able to
    > > reload it.
    > > Thanks!
    > > --
    > > Paul G
    > > Software engineer.
    > >
    > >
    > >
    > > "Alexey Smirnov" wrote:
    > > > On Jun 17, 10:28 pm, Paul <> wrote:
    > > > > Hi, thanks for the response.
    > > > > I tried adding
    > > > > <body onunload="opener.location.href=opener.location.href;"></body>
    > > > > to the source of the second page but get the error
    > > > > element body can not be nested within element td. I placed the code as
    > > > > follows in the second form aspx file.

    > >
    > > > > <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
    > > > > Runat="Server">

    > >
    > > > > <body onunload="opener.location.href=opener.location.href;"></body>

    > >
    > > > > followed by several html tables.
    > > > > Anyhow just wondering where to place the body tag?

    > >
    > > > > Also the way the user gets to the second page from the first page is just a
    > > > > hyperlink.
    > > > > thanks.

    > >
    > > > > --
    > > > > Paul G
    > > > > Software engineer.

    > >
    > > > > "Alexey Smirnov" wrote:
    > > > > > On Jun 17, 9:19 pm, Paul <> wrote:
    > > > > > > Hi I tried a google search but could not find anything. I am trying to cause
    > > > > > > one webpage to reload when a second web page is closed. The second webpage
    > > > > > > loads data into a session variable and when closed I need to reload the first
    > > > > > > page loading in the data from the session variable. Since I need to close
    > > > > > > the sescond form just setting the post back url to the first page on the
    > > > > > > close button from the second page is not quite what I am looking for.
    > > > > > > --
    > > > > > > Paul G
    > > > > > > Software engineer.

    > >
    > > > > > Hi Paul,

    > >
    > > > > > Try to add the following code to your second web page

    > >
    > > > > > <body onunload="opener.location.href=opener.location.href;">

    > >
    > > > > > You might be also interested to see the following thread
    > > > > >http://forums.asp.net/t/988319.aspx

    > >
    > > > > > Hope this helps- Hide quoted text -

    > >
    > > > > - Show quoted text -

    > >
    > > > The BODY element contains all the content of a document, including TD
    > > > and TABLE. It can be nested within HTML element only. It seems that
    > > > you are using Master page and it means you should change a BODY
    > > > element of the Master page. If Master page is used for many Content
    > > > pages then you can either make a copy of it (to apply changes to the
    > > > BODY tag), or you can set your Master page body tag to:

    > >
    > > > <body id="mBody" runat="server">

    > >
    > > > Then add this on the page that has to be closed:

    > >
    > > > public void Page_Load(Object sender, EventArgs e)
    > > > {
    > > > HtmlGenericControl body =
    > > > (HtmlGenericControl)Master.FindControl("mBody");
    > > > body.Attributes.Add("onunload",
    > > > "opener.location.href=opener.location.href;");
    > > > }

    > >
    > > > I didn't test it, but I think it should work.- Hide quoted text -

    > >
    > > - Show quoted text -

    >
    > Great! :)
    >
    Paul, Jun 17, 2008
    #8
  9. On Jun 18, 12:08 am, Paul <> wrote:
    > Hi just had one last question.  Not sure if there is anything that can be
    > done about this but when webpage 2 reloads (I have some controls that
    > postback) It also causes webpage 1 to reload.  Is there anyway to have page
    > one reload only when page two is closed?  I guess the onunload event must
    > occure when page 2 postsback to the server? Thanks.
    > HtmlGenericControl body =
    >
    > (HtmlGenericControl)Master.FindControl("MasterPageBodyTag");
    >                    body.Attributes.Add("onunload",
    >                   "opener.location.href=opener.location.href;");
    > --
    > Paul G
    > Software engineer.
    >
    >
    >
    > "Alexey Smirnov" wrote:
    > > On Jun 17, 11:25 pm, Paul <> wrote:
    > > > Hi, It works! I guess it must know what the parent window is to be able to
    > > > reload it.
    > > > Thanks!
    > > > --
    > > > Paul G
    > > > Software engineer.

    >
    > > > "Alexey Smirnov" wrote:
    > > > > On Jun 17, 10:28 pm, Paul <> wrote:
    > > > > > Hi, thanks for the response.
    > > > > > I tried adding
    > > > > > <body onunload="opener.location.href=opener.location.href;"></body>
    > > > > > to the source of the second page but get the error
    > > > > > element body can not be nested within element td.  I placed the code as
    > > > > > follows in the second form aspx file.

    >
    > > > > > <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
    > > > > > Runat="Server">

    >
    > > > > >   <body onunload="opener.location.href=opener.location.href;"></body>

    >
    > > > > > followed by several html tables.
    > > > > > Anyhow just wondering where to place the body tag?

    >
    > > > > > Also the way the user gets to the second page from the first page is just a
    > > > > > hyperlink.
    > > > > > thanks.

    >
    > > > > > --
    > > > > > Paul G
    > > > > > Software engineer.

    >
    > > > > > "Alexey Smirnov" wrote:
    > > > > > > On Jun 17, 9:19 pm, Paul <> wrote:
    > > > > > > > Hi I tried a google search but could not find anything.  I am trying to cause
    > > > > > > > one webpage to reload when a second web page is closed.  The second webpage
    > > > > > > > loads data into a session variable and when closed I need to reload the first
    > > > > > > > page loading in the data from the session variable.  Since I need to close
    > > > > > > > the sescond form just setting the post back url to the first page on the
    > > > > > > > close button from the second page is not quite what I am looking for.
    > > > > > > > --
    > > > > > > > Paul G
    > > > > > > > Software engineer.

    >
    > > > > > > Hi Paul,

    >
    > > > > > > Try to add the following code to your second web page

    >
    > > > > > > <body onunload="opener.location.href=opener.location.href;">

    >
    > > > > > > You might be also interested to see the following thread
    > > > > > >http://forums.asp.net/t/988319.aspx

    >
    > > > > > > Hope this helps- Hide quoted text -

    >
    > > > > > - Show quoted text -

    >
    > > > > The BODY element contains all the content of a document, including TD
    > > > > and TABLE. It can be nested within HTML element only. It seems that
    > > > > you are using Master page and it means you should change a BODY
    > > > > element of the Master page. If Master page is used for many Content
    > > > > pages then you can either make a copy of it (to apply changes to the
    > > > > BODY tag), or you can set your Master page body tag to:

    >
    > > > > <body id="mBody" runat="server">

    >
    > > > > Then add this on the page that has to be closed:

    >
    > > > > public void Page_Load(Object sender, EventArgs e)
    > > > > {
    > > > > HtmlGenericControl body =
    > > > > (HtmlGenericControl)Master.FindControl("mBody");
    > > > > body.Attributes.Add("onunload",
    > > > > "opener.location.href=opener.location.href;");
    > > > > }

    >
    > > > > I didn't test it, but I think it should work.- Hide quoted text -

    >
    > > > - Show quoted text -

    >
    > > Great! :)- Hide quoted text -

    >
    > - Show quoted text -


    Hi Paul

    The onUnload event is handled when you refresh the page as well.
    So, to make your code triggered on close only you can try following:

    1) add the following js-code to your Master page between <head> and </
    head>

    <script>
    function doUnload()
    {
    if (window.event.clientX < 0 && window.event.clientY < 0)
    {
    opener.location.href=opener.location.href;
    }
    }
    </script>

    2) change code-behind, from

    body.Attributes.Add("onunload",
    "opener.location.href=opener.location.href;");

    to

    body.Attributes.Add("onunload", "doUnload();");

    That should avoid the refresh of the parent window if child window has
    been refreshed.
    I hope it works

    Cheers!

    Alexey Smirnov [MVP]
    Alexey Smirnov, Jun 18, 2008
    #9
  10. Paul

    Paul Guest

    Hi, thanks for the additional response. I tried the following but now it
    appears that the first page is not reloading now but even when I close the
    second page. To close the second page I am using an input button with the
    following
    <input id="btn_close" type="button" value="Close" onclick ="window.close()"
    style="width: 100px" class="Button_sm" />.

    Here is the code I added as specified, in the master page I added between
    the head tags.
    <script type="text/javascript">
    function doUnload()
    {
    if (window.event.clientX < 0 && window.event.clientY < 0)
    {
    opener.location.href=opener.location.href;
    }
    }
    </script>

    In the code behind on the second webform (the one that when closed should
    cause the first page to refresh)

    HtmlGenericControl body =

    (HtmlGenericControl)Master.FindControl("MasterPageBodyTag");
    body.Attributes.Add("onunload", "doUnload();");
    thanks.

    --
    Paul G
    Software engineer.
    Paul, Jun 18, 2008
    #10
  11. On Jun 18, 6:28 pm, Paul <> wrote:
    > Hi, thanks for the additional response.  I tried the following but now it
    > appears that the first page is not reloading now but even when I close the
    > second page.  To close the second page I am using an input button with the
    > following
    > <input id="btn_close" type="button" value="Close" onclick ="window.close()"
    > style="width: 100px" class="Button_sm" />.
    >
    > Here is the code I added as specified, in the master page I added between
    > the head tags.
    >  <script  type="text/javascript">
    > function doUnload()
    > {
    >  if (window.event.clientX < 0 && window.event.clientY < 0)
    >  {
    >    opener.location.href=opener.location.href;
    >  }}
    >
    > </script>
    >
    > In the code behind on the second webform (the one that when closed should
    > cause the first page to refresh)
    >
    >  HtmlGenericControl body =
    >
    > (HtmlGenericControl)Master.FindControl("MasterPageBodyTag");
    >                              body.Attributes.Add("onunload", "doUnload();");  
    > thanks.
    >
    > --
    > Paul G
    > Software engineer.


    Paul, if you programmatically close the page by onclick
    ="window.close()" then it would be much easier to add the refresh call
    directly to the onclick call. Try it

    onclick="javascript:eek:pener.location.href=opener.location.href;window.close();"
    Alexey Smirnov, Jun 18, 2008
    #11
  12. Paul

    Paul Guest

    Hi Alexey,thanks for the additional information, that seemed to do the trick.
    I probably should have mentioned I was closing form 2 programatically. Have
    another minor issue, on webform one I am reading reading a session variable
    which works now. The session variable is a generic list with a simple
    structure as a datatype. The problem is on webform one when I try to display
    it in a gridview control I get the error (datasource for gridview does not
    have any properties or attributes from which to generate columns). For the
    code I have

    genericlist = (List<structRepo>)Session["genericlist"];
    if (genericlist != null)
    {
    gridview.DataSource = genericlist;//
    gvRepository.DataBind();
    }
    I also have the genericlist declared as public.

    --
    Paul G
    Software engineer.


    "Alexey Smirnov" wrote:

    > On Jun 18, 6:28 pm, Paul <> wrote:
    > > Hi, thanks for the additional response. I tried the following but now it
    > > appears that the first page is not reloading now but even when I close the
    > > second page. To close the second page I am using an input button with the
    > > following
    > > <input id="btn_close" type="button" value="Close" onclick ="window.close()"
    > > style="width: 100px" class="Button_sm" />.
    > >
    > > Here is the code I added as specified, in the master page I added between
    > > the head tags.
    > > <script type="text/javascript">
    > > function doUnload()
    > > {
    > > if (window.event.clientX < 0 && window.event.clientY < 0)
    > > {
    > > opener.location.href=opener.location.href;
    > > }}
    > >
    > > </script>
    > >
    > > In the code behind on the second webform (the one that when closed should
    > > cause the first page to refresh)
    > >
    > > HtmlGenericControl body =
    > >
    > > (HtmlGenericControl)Master.FindControl("MasterPageBodyTag");
    > > body.Attributes.Add("onunload", "doUnload();");
    > > thanks.
    > >
    > > --
    > > Paul G
    > > Software engineer.

    >
    > Paul, if you programmatically close the page by onclick
    > ="window.close()" then it would be much easier to add the refresh call
    > directly to the onclick call. Try it
    >
    > onclick="javascript:eek:pener.location.href=opener.location.href;window.close();"
    >
    Paul, Jun 18, 2008
    #12
  13. On Jun 18, 9:53 pm, Paul <> wrote:
    > Hi Alexey,thanks for the additional information, that seemed to do the trick.
    >  I probably should have mentioned I was closing form 2 programatically.  Have
    > another minor issue, on webform one I am reading reading a session variable
    > which works now.  The session variable is a generic list with a simple
    > structure as a datatype.  The problem is on webform one when I try to display
    > it in a gridview control I get the error (datasource for gridview does not
    > have any properties or attributes from which to generate columns).  For the
    > code I have
    >
    >  genericlist = (List<structRepo>)Session["genericlist"];
    >                 if (genericlist != null)
    >                 {
    >                     gridview.DataSource = genericlist;//                    
    >         gvRepository.DataBind();
    >                 }
    > I also have the genericlist declared as public.
    >



    Hi Paul,

    if using a GridView with AutoGenerateColumns="True" the data source
    expected to get properties to generate the columns of the grid. You
    can either, use a GridView with BoundColumns specified for required
    columns

    <asp:GridView AutoGenerateColumns="false"...
    <Columns>
    <asp:BoundField DataField="..."

    or you should update the structRepo class to return properties for
    each field

    e.g.

    private int _list_id;

    public int list_id {
    get {
    return _list_id
    }
    set {
    _list_id = value
    }
    }

    Please take a look at the following link (the definition for the
    public class Person)
    http://unboxedsolutions.com/sean/archive/2005/01/22/428.aspx

    Hope it helps
    Alexey Smirnov, Jun 19, 2008
    #13
  14. Paul

    Paul Guest

    Hi Alexey, thanks for the additional information. I tried setting the
    AutoGenerateColumns="False" and then adding bound columns and setting the
    datasource name to the same as the names of the items in the structure, but
    that did not seem to work as it could not find the name. I will try setting
    up properties and setting the autogencolumns to true.

    Paul G
    Software engineer.


    "Alexey Smirnov" wrote:

    > On Jun 18, 9:53 pm, Paul <> wrote:
    > > Hi Alexey,thanks for the additional information, that seemed to do the trick.
    > > I probably should have mentioned I was closing form 2 programatically. Have
    > > another minor issue, on webform one I am reading reading a session variable
    > > which works now. The session variable is a generic list with a simple
    > > structure as a datatype. The problem is on webform one when I try to display
    > > it in a gridview control I get the error (datasource for gridview does not
    > > have any properties or attributes from which to generate columns). For the
    > > code I have
    > >
    > > genericlist = (List<structRepo>)Session["genericlist"];
    > > if (genericlist != null)
    > > {
    > > gridview.DataSource = genericlist;//
    > > gvRepository.DataBind();
    > > }
    > > I also have the genericlist declared as public.
    > >

    >
    >
    > Hi Paul,
    >
    > if using a GridView with AutoGenerateColumns="True" the data source
    > expected to get properties to generate the columns of the grid. You
    > can either, use a GridView with BoundColumns specified for required
    > columns
    >
    > <asp:GridView AutoGenerateColumns="false"...
    > <Columns>
    > <asp:BoundField DataField="..."
    >
    > or you should update the structRepo class to return properties for
    > each field
    >
    > e.g.
    >
    > private int _list_id;
    >
    > public int list_id {
    > get {
    > return _list_id
    > }
    > set {
    > _list_id = value
    > }
    > }
    >
    > Please take a look at the following link (the definition for the
    > public class Person)
    > http://unboxedsolutions.com/sean/archive/2005/01/22/428.aspx
    >
    > Hope it helps
    >
    Paul, Jun 19, 2008
    #14
  15. On Jun 19, 4:51 pm, Paul <> wrote:
    > Hi Alexey, thanks for the additional information.  I tried setting the
    > AutoGenerateColumns="False" and then adding bound columns and setting the
    > datasource name to the same as the names of the items in the structure, but
    > that did not seem to work as it could not find the name.  I will try setting
    > up properties and setting the autogencolumns to true.
    >
    > Paul G
    > Software engineer.
    >
    >
    >
    > "Alexey Smirnov" wrote:
    > > On Jun 18, 9:53 pm, Paul <> wrote:
    > > > Hi Alexey,thanks for the additional information, that seemed to do the trick.
    > > >  I probably should have mentioned I was closing form 2 programatically.  Have
    > > > another minor issue, on webform one I am reading reading a session variable
    > > > which works now.  The session variable is a generic list with a simple
    > > > structure as a datatype.  The problem is on webform one when I try to display
    > > > it in a gridview control I get the error (datasource for gridview does not
    > > > have any properties or attributes from which to generate columns).  For the
    > > > code I have

    >
    > > >  genericlist = (List<structRepo>)Session["genericlist"];
    > > >                 if (genericlist != null)
    > > >                 {
    > > >                     gridview.DataSource = genericlist;//                    
    > > >         gvRepository.DataBind();
    > > >                 }
    > > > I also have the genericlist declared as public.

    >
    > > Hi Paul,

    >
    > > if using a GridView with AutoGenerateColumns="True" the data source
    > > expected to get properties to generate the columns of the grid. You
    > > can either, use a GridView with BoundColumns specified for required
    > > columns

    >
    > > <asp:GridView AutoGenerateColumns="false"...
    > > <Columns>
    > > <asp:BoundField DataField="..."

    >
    > > or you should update the structRepo class to return properties for
    > > each field

    >
    > > e.g.

    >
    > > private int _list_id;

    >
    > > public int list_id {
    > >   get {
    > >     return _list_id
    > >   }
    > >   set {
    > >     _list_id = value
    > >   }
    > > }

    >
    > > Please take a look at the following link (the definition for the
    > > public class Person)
    > >http://unboxedsolutions.com/sean/archive/2005/01/22/428.aspx

    >
    > > Hope it helps- Hide quoted text -

    >
    > - Show quoted text -


    ah, true, I think you're right and at first you have to set properties
    to bind the grid
    Alexey Smirnov, Jun 19, 2008
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Hunsley
    Replies:
    4
    Views:
    8,348
    Alex Hunsley
    Sep 6, 2004
  2. Joshua Beall
    Replies:
    26
    Views:
    220,263
    AndreiKaa
    Jun 29, 2007
  3. gen_tricomi
    Replies:
    2
    Views:
    734
    gen_tricomi
    May 23, 2006
  4. Matt Kruse
    Replies:
    5
    Views:
    307
    Richard Cornford
    Sep 9, 2003
  5. Stefan Mueller
    Replies:
    4
    Views:
    292
    Stefan Mueller
    Nov 5, 2005
Loading...

Share This Page