Hi all,
I'm writing a small web application which searches a database based on
a date field, and populates a datagrid control with the results. The
datagrid control has selection buttons added to it to view additional
details about the selected result (a second database query is
triggered).
I want this second query to pop up in a new window, the way it would
if I used "window.ope n" in javascript. I've added a function in the
javascript to open the new window ("newpage"), but this function does
not appear to be visible to the c# code on the asp page.
I must admit to being a little confused about the separation between
the c# code view of the asp page and the html view of the page layout
- these two things are interrelated, but there doesn't seem to be any
easy way to get them to talk to one another.
To illustrate, this is the html view of the page Query.aspx:
---
<%@ Page language="c#" Codebehind="Que ry.aspx.cs"
AutoEventWireup ="false" Inherits="Video Search.WebForm1 " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
<script>
function newpage(string url)
{
window.open(url , 'Session Detail', 'width=400,heig ht=400,
toolbar=no');
}
</script>
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:Calendar id="Calendar1" style="Z-INDEX: 101; LEFT: 296px;
POSITION: absolute; TOP: 112px"
runat="server" Width="240px" Height="224px"> </asp:Calendar>
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 106; LEFT: 56px;
POSITION: absolute; TOP: 488px"
runat="server" Width="680px" Height="280px"
HorizontalAlign ="Left" BorderColor="#9 99999" BorderStyle="So lid"
CellSpacing="2" BorderWidth="3p x" BackColor="#CCC CCC"
CellPadding="4" ForeColor="Blac k">
<SelectedItemSt yle Font-Bold="True" ForeColor="Whit e"
BackColor="#000 099"></SelectedItemSty le>
<ItemStyle BackColor="Whit e"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="Whit e"
BackColor="Blac k"></HeaderStyle>
<FooterStyle BackColor="#CCC CCC"></FooterStyle>
<Columns>
<asp:ButtonColu mn Text="View Session"
ButtonType="Pus hButton" CommandName="Se lect"></asp:ButtonColum n>
</Columns>
<PagerStyle HorizontalAlign ="Left" ForeColor="Blac k"
BackColor="#CCC CCC" Mode="NumericPa ges"></PagerStyle>
</asp:DataGrid>
<asp:Label id="Label2" style="Z-INDEX: 103; LEFT: 440px;
POSITION: absolute; TOP: 64px" runat="server"
Width="96px" Height="32px">T o:</asp:Label>
<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 128px;
POSITION: absolute; TOP: 72px" runat="server"
Width="96px" Height="32px">F rom:</asp:Label>
<asp:Button id="Button1" style="Z-INDEX: 104; LEFT: 320px;
POSITION: absolute; TOP: 408px" runat="server"
Width="184px" Height="40px" Text="Search!"> </asp:Button>
<asp:Label id="Label3" style="Z-INDEX: 105; LEFT: 128px;
POSITION: absolute; TOP: 24px" runat="server"
Width="280px" Height="24px">S earch for video
records:</asp:Label>
<asp:Label id="errortext" style="Z-INDEX: 107; LEFT: 88px;
POSITION: absolute; TOP: 360px"
runat="server" Width="624px" Height="38px"></asp:Label>
</form>
</body>
</HTML>
This is the button handler event for the selection buttons in the data
grid, which is in Query.aspx.cs:
private void DataGrid1_Selec tedIndexChanged (object sender,
System.EventArg s e)
{
DataGridItem sel = DataGrid1.Selec tedItem;
string segmentid = sel.Cells[2].Text;
newpage("Search Results.aspx?se g=" + segmentid);
}
---
Can I access the javascript function "newpage" from the c# source like
this?
Is there a better way to do this?
Any help would be greatly appreciated.
Cheers,
Alex.
Remove ernie and bert from email address to reply.