Hi,
I'm using SelectedIndexChanged on a gridview row to trigger an event which is working fine in a normal webform. But, when I included "master page", it's not triggering the same event.
everything is same except, I added MasterPageFile location & removed FORM tag.
what is the reason that it's not triggering event. Greatly appreciate any help.
ASP code
<%@ page title="" language="C" masterpagefile="~/site.master codebehind="test.aspx.cs" inherits="Main.test" enableEventValidation="false"
autoeventwireup="true"%>
<asp:content ID="content1" contentplaceholderid="headcontent" runat="server">
<link href="styles/CS1.css" rel="stylesheet" type="text/css"/>
<asp:content/>
<asp:content ID="content2" contentplaceholderid="maincontent" runat="server">
<asp:gridview id="GV1" runat="server" selected index="1" onselectedindexchanged="GV1_SelectedIndexChanged" onrowdatabound="GV1_rowdatabound">
<Columns>
<ASP:boundfield datafield="column1" headerText="Column1"/>
<ASP:boundfield datafield="column2" headerText="Column2"/>
<ASP:boundfield datafield="column3" headerText="Column3"/>
<ASP:commandfield showselectButton="true" buttontype="Link" visible="false" selecttext="Enroll"/>
</columns>
<selectedrowstyle backcolor="gray"/>
</asp:gridview>
<asp:gridview id="GV2" runat="server">
</asp:gridview>
<asp:content/>
code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using system.web.services;
namespace Main
{
public partial class test : System.Web.UI.Page
{
datatable mydatatable = new datatable();
datacolumn mydatacolumn = new datacolumn();
const string key = "MyDataSource";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
builddatatable1();
}
}
private void builddatatable1()
{
if (Session[key] == null)
{
gridView1.DataSource = GetDataSource();
gridView1.DataBind();
}
else
{
gridView1.DataSource = (DataTable)Session[key];
gridView1.DataBind();
}
}
protected DataTable GetDataSource()
{
try
{
mydatacolumn = new datacolumn();
mydatacolumn.columnname = "Column1";
mydatacolumn.datatype = system.type.gettype("system.string");
mydatatable.columns.add(mydatacolumn);
mydatacolumn = new datacolumn();
mydatacolumn.columnname = "Column2";
mydatacolumn.datatype = system.type.gettype("system.string");
mydatatable.columns.add(mydatacolumn);
mydatacolumn = new datacolumn();
mydatacolumn.columnname = "Column3";
mydatacolumn.datatype = system.type.gettype("system.string");
mydatatable.columns.add(mydatacolumn);
mydatatable.rows.add(datarow);
datarow = mydatatable.newrow();
datarow["Column1"] = "Row1_col1"
datarow["Column2"] = "Row1_col2"
datarow["Column3"] = "Row1_col3"
mydatatable.rows.add(datarow);
datarow = mydatatable.newrow();
datarow["Column1"] = "Row2_col1"
datarow["Column2"] = "Row2_col2"
datarow["Column3"] = "Row2_col3"
mydatatable.rows.add(datarow);
Session[key] = mydatatable;
return mydatatable;
}
catch
{
return null;
}
}
protected void GV1_SelectedIndexChaged(object sender, EventArgs e)
{
if (GV1.selectedrow.cells[1].text !=null)
{
GV2.datasource = getdatasource();
GV2.databind();
}
}
}
}
master page code
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="Main.Application.Site" %>
<%@ Register TagPrefix="uc" TagName="MenuItems" Src="~/MenuItems.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="~/Styles/global.css" runat="server"
id="Lnk1" />
<link href="~/Styles/CS1.css" rel="stylesheet" type="text/css" runat="server" id="Lnk2" />
<!--[if IE 7]><link rel="stylesheet" type="text/css" href="~/Styles/IE7.css" /><![endif]-->
<title>test</title>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
<style type="text/css">
@font-face
{
font-family: "Frutiger Neue W01 Light";
src: url("fonts/12d6929b-8b96-4898-b413-6bd6d0e2d0fb.eot?iefix") format("eot");
}
@font-face
{
font-family: "Frutiger Neue W01 Light";
src: url("fonts/12d6929b-8b96-4898-b413-6bd6d0e2d0fb.eot?iefix");
src: url("//:") format("no404"),url("fonts/a2afa464-03b1-4a6c-b5cb-3521a1cf94ba.woff") format("woff"),url("fonts/9aa255d9-7d3d-420a-bb79-2f91c4aed10f.ttf") format("truetype"),url("fonts/b755ea1d-fab9-4588-b7a8-31350efb38f9.svg#b755ea1d-fab9-4588-b7a8-31350efb38f9") format("svg");
}
@font-face
{
font-family: "Frutiger Neue W01 Md";
src: url("fonts/979450a2-8d59-4cc2-9937-94255a4f3923.eot?iefix") format("eot");
}
@font-face
{
font-family: "Frutiger Neue W01 Md";
src: url("fonts/979450a2-8d59-4cc2-9937-94255a4f3923.eot?iefix");
src: url("//:") format("no404"),url("fonts/4748e3d8-1b23-420a-a419-d7a367ea1076.woff") format("woff"),url("fonts/11f76f62-1d4f-4327-bce7-1eee2aba08bf.ttf") format("truetype"),url("fonts/ce4a6e96-f298-4ab1-a2ac-bdbbbc1467d6.svg#ce4a6e96-f298-4ab1-a2ac-bdbbbc1467d6") format("svg");
}
@font-face
{
font-family: "FrutigerNeueW01-Regular";
src: url("fonts/e2e74e1c-9e18-4127-adfd-feb8f6a9ceaf.eot?iefix") format("eot");
}
@font-face
{
font-family: "FrutigerNeueW01-Regular";
src: url("fonts/e2e74e1c-9e18-4127-adfd-feb8f6a9ceaf.eot?iefix");
src: url("//:") format("no404"),url("fonts/aa94077e-cdcd-4e33-abe0-ddcfe27e3485.woff") format("woff"),url("fonts/22dfb43f-26df-46f9-aa0f-30038f8da834.ttf") format("truetype"),url("fonts/36ad2de1-95ea-4eb3-a836-29c86179a248.svg#36ad2de1-95ea-4eb3-a836-29c86179a248") format("svg");
}
@font-face
{
font-family: "DIN Next W01 Light";
src: url("fonts/3e0b2cd7-9657-438b-b4af-e04122e8f1f7.eot?iefix") format("eot");
}
@font-face
{
font-family: "DIN Next W01 Light";
src: url("fonts/3e0b2cd7-9657-438b-b4af-e04122e8f1f7.eot?iefix");
src: url("//:") format("no404"),url("fonts/bc176270-17fa-4c78-a343-9fe52824e501.woff") format("woff"),url("fonts/3516f91d-ac48-42cd-acfe-1be691152cc4.ttf") format("truetype"),url("fonts/d1b1e866-a411-42ba-8f75-72bf28e23694.svg#d1b1e866-a411-42ba-8f75-72bf28e23694") format("svg");
}
@font-face
{
font-family: "DIN Next W01 Medium";
src: url("fonts/324dee78-6585-4c13-8ca3-5817cc600d84.eot?iefix") format("eot");
}
@font-face
{
font-family: "DIN Next W01 Medium";
src: url("fonts/324dee78-6585-4c13-8ca3-5817cc600d84.eot?iefix");
src: url("//:") format("no404"),url("fonts/4bf0ead4-e61b-4992-832b-6ff05828d99f.woff") format("woff"),url("fonts/73713a0b-8f6a-4c4e-b8a8-7cf238e632f6.ttf") format("truetype"),url("fonts/b90b6bdf-15e2-4544-9fe0-92c79fff0ecd.svg#b90b6bdf-15e2-4544-9fe0-92c79fff0ecd") format("svg");
}
@font-face
{
font-family: "DIN Next W01 Regular";
src: url("fonts/da088ecc-a53c-4831-a95b-6fd81b5b338a.eot?iefix") format("eot");
}
@font-face
{
font-family: "DIN Next W01 Regular";
src: url("fonts/da088ecc-a53c-4831-a95b-6fd81b5b338a.eot?iefix");
src: url("//:") format("no404"),url("fonts/c5a7f89e-15b6-49a9-8259-5ea665e72191.woff") format("woff"),url("fonts/868c94b5-ca49-46b7-b62b-297f8d861125.ttf") format("truetype"),url("fonts/e3145f65-29b5-4f7f-8c6e-2dc135021b6a.svg#e3145f65-29b5-4f7f-8c6e-2dc135021b6a") format("svg");
}
@font-face
{
font-family: "DIN Next W02 Bold";
src: url("fonts/50d13d4e-96c6-4412-a8fa-baa4814c5332.eot?iefix") format("eot");
}
@font-face
{
font-family: "DIN Next W02 Bold";
src: url("fonts/50d13d4e-96c6-4412-a8fa-baa4814c5332.eot?iefix");
src: url("//:") format("no404"),url("fonts/109143ca-57fb-459c-9814-3a68f0245ac3.woff") format("woff"),url("fonts/c9fa50e2-c243-451a-b91b-ee74f341d7a8.ttf") format("truetype"),url("fonts/1201bd6f-15f5-4b51-9c6f-c5c4b35d31f5.svg#1201bd6f-15f5-4b51-9c6f-c5c4b35d31f5") format("svg");
}
</style>
</head>
<body id="bodyTag">
<form id="Form1" runat="server">
<div id="GlobalNav" class="light" style="border:1px solid #fff;height:80px;">
<!-- Menu Control here -->
<uc:menuitems id="MItems" runat="Server" style="position: absolute;"></uc:menuitems>
<div id="HeaderLines" class="HeaderLine">
<div style="margin-left: 43px !important; padding-bottom:2px;">
<div style="margin-top:30px;">
<asp:Label ID="WelcomeMsg" runat="server" ></asp:Label>
<asp:LinkButton runat="server" ID="Logout" OnClick="Logout_OnClick" CausesValidation="false">
</asp:LinkButton></div>
</div>
</div>
</div>
<div class="placeHolder">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<div class="clear"> </div>
<div id="globalFooter">
<div class="grid">
<ul class="secondary">
<li>©1994-<span id="currentYear">2010</span> Main.</li>
</ul>
<ul class="primary">
<li class="first"><a href="http://www.Main.com/us/company/en/index.html">About Main</a></li>
<li class="policy"><a href="http://www.Main.us/privacy/">Global Privacy Policy</a></li>
<li id="testTermsLi" runat="server" visible="false"><a runat="server" id="testTermsLink"
href="~/testTerms.htm" target="_blank">test Terms of Use</a></li>
<li class="policy"><a href="http://www.Main.us/terms-of-use.html">Terms of Use</a></li>
<li><a href="ContactUs.aspx">Contact us</a></li>
</ul>
<p class="cust-service">Customer Service: 1-800-123-4567 </p>
</div>
</div>
<script type="text/javascript">
(function () {
document.getElementById("currentYear").innerHTML = new Date().getFullYear();
} ());
// to hide the vertical line when there is no welcome message
if (document.getElementById("WelcomeMsg") == null) {
document.getElementById("HeaderLines").className = "";
}
//get a hold of the timers
var idleTimeoutWarning = null;
var idleTimeout = null;
//this function will automatically be called by ASP.NET AJAX when page is loaded and partial postbacks complete
function pageLoad() {
//clear out any old timers from previous postbacks
if (idleTimeoutWarning != null)
clearTimeout(idleTimeoutWarning);
if (idleTimeout != null)
clearTimeout(idleTimeout);
//read time for session timeout
var sessionTimeout = <%= Session.Timeout %>;
var millisecTimeOutWarning = (parseInt(sessionTimeout) - 1) * 60 * 1000;
var millisecTimeOut = parseInt(sessionTimeout) * 60 * 1000;
//set a timeout to display warning if user has been inactive
//idleTimeoutWarning = setTimeout("DisplayIdleWarning()", millisecTimeOutWarning);
idleTimeout = setTimeout("TimeoutPage()", millisecTimeOut);
}
function DisplayIdleWarning() {
alert("Your session is about to expire due to inactivity.");
}
function TimeoutPage() {
//refresh page for this sample, we could redirect to another page that has code to clear out session variables
alert("Your session is expired due to inactivity.");
location.href = '<%= Page.ResolveUrl("~/Default.aspx") %>';
// location.reload();
}
</script>
</form>
</body>
</html>