Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

opening a new window, range of options = multiple destinations 1

Status
Not open for further replies.

lastdonuk

Programmer
Jan 19, 2005
58
GB
Hi,

Hoping someone can help. I've got an ASPX page with a number of asp:ImageButtons triggering javascript window.open functions to open various new windows dependent on the button clicked.

My issue is that the "parent" page - i.e. where the button_click is triggered from - always refreshes. I realize this is going to happen unless I use PostBackUrl BUT my question is:

How can I run multiple PostBackUrls from a single page, because the first command seems to override all others, by which I mean all button_clicks perform the same open window action - rerunning a chart, for example.

I should use if (!IsPostBack) around everything I think, but where in the Code Behind?

Any assistance gratefully received (this is a .NET 2.0 project in C#, btw)...

Cheers!
Bob

lastdonuk
Powergirls Ltd
 
instead of image buttons just wrap the image with a hyperlink
Code:
<asp:Hyperlink target="blank" navigateurl="apage.aspx?..." text="" viewstate=false>
   <asp:Image source="" enableviewstate="false" />
</asp:Hyperlink>

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Cheers Jason,

Just to check: as there's no onClick method for asp:Hyperlink, I can just do Attributes.Add("onClick"...) for my Code Behind to fire, I have to do some variable storage, variable updates, etc...?

My understanding is growing, I just need someone to say "yeah, that's correct"!

Thanks again,
Bob

lastdonuk
Powergirls Ltd
 
no that would not be the appropiate action. what exactly are you doing?
1. render page
2.a. postback to set values
2.b. open new browser window
is this correct?
this can work, but it's clunky for a web based application. What do you want to do with this page and the child windows?

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Here's the scenario at present:

1. Render parent page
2. Render Chart on GridView SelectedIndexChanged
3. Open "Full Screen" version of Chart via Button_Click in a new window using asp:ImageButton onClick to set Cache variables and onClientClick to run the javascript:popUpWin('PopUp.aspx') code

This all works fine BUT when the new window opens, the parent page "runs" again but the original chartdoesn't render, making the parent page look "wrong" with a missing chart.

In essence, I want to stop the parent page refreshing itself when a new window opens - this is why I've been looking at PostBackUrl and if !IsPostBack, etc...

Any help gratefully received, I can't believe what I'm trying to do is so difficult, I've done it a million times in classic ASP! ;)

Cheers,
Bob

lastdonuk
Powergirls Ltd
 
asp.net has a life cycle which is a hack on stateless enviornments to provide a form of statefulness.

this can throw people for a loop when they first start developing with asp.net. I'll get back to the original question this afternoon as i'm in and out of meetings this morning.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
ok so when the user clicks a link/button/control you want to render a chart in a new window.
here is how I would configure the forms
Code:
<asp:gridview id="MyGrid">
   <columns>
      <template column>
         <item template>
            <asp:HyperLink target="blank" navigateurl='<%#Eval("id", "viewchart.aspx?id={0}")%>'>
               <asp:Image imagesource="path to image" />
            </asp:HyperLink>
         </item template>
      </template column>
   </columns>
</asp:gridview>
Code:
page_load(object sender, event args e)
{
   if(!IsPostBack)
   {
      MyGrid.DataSource = GetData();
      MyGrid.DataBind();
   }
}
Code:
page_load(object sender, event args e)
{
   if(!IsPostBack)
   {
      int id = int.Parse(Request.QueryString["id"]);
      CreateChart(id);
      DisplayChart(id);
   }
}
now this is assuming alot about your pages, but basically your 1st page (page 1) will render a gridview with a hyperlink wrapping an image. when this link is clicked a new windows will open to "viewchart" page and pass an id in the query string so we know which chart to update/display.
the viewchart page is responsible for creating the chart and displaying it.
How that's done is up to you. in the example above I created to private members one to create the chart, another to load the chart into the html.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks,

I really appreciate your help and explanations here.

My example is a little different - the new page is called from a button outside the chart and the gridview - but I'm sure the principle is the same, so I'll see if I can apply the logic to my scenario and thanks alot once again...

I'll update with any progress/info when I can.

Cheers!
Bob

lastdonuk
Powergirls Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top