|
Hi,
How i can call javascript OK function in click event of btnOK :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GridviewGhataKhadamat.aspx.cs"
Inherits="Tina.WebUI.WorkFlows.Forms.Khadamat.GridviewGhataKhadamat" %>
<!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">
<title></title>
<script type="text/javascript">
function Close() {
window.close();
}
function OK(Id,Name,Code) {
var vReturnValue = new Object();
vReturnValue.Id = Id;
vReturnValue.Name = Name;
vReturnValue.Code = Code;
window.returnValue = vReturnValue;
window.close();
}
</script>
</head>
<body >
<form id="form1" runat="server">
<div>
<%----%>
<asp:GridView ID="gvGhataKhadamat" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#CC9966" BorderStyle="Inset" BorderWidth="1px" CellPadding="4" Font-Names="Verdana">
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<Columns>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<input name="rbGhataKhadamat" type="radio" value="<%# Eval("Id") %>,<%# Eval("Name") %>,<%# Eval("Code") %>" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Id" HeaderText="ID" Visible="false" />
<asp:BoundField DataField="Code" HeaderText="<%$ Resources:Khadamat, Code %>" />
<asp:BoundField DataField="Name" HeaderText="<%$ Resources:Khadamat, Name %>" />
</Columns>
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
</asp:GridView>
</div>
<asp:Button runat="server" ID="btnOk" Text="<%$ Resources:Khadamat, ok %>"
OnClick="btnOk_Click"/>
<asp:Button runat="server" ID="btnCancel" Text="<%$ Resources:Khadamat, cancel %>"
OnClientClick="Close()" />
</form>
</body>
</html>
and this is bihind code
protected void btnOk_Click(object sender, EventArgs e)
{
string[] strSelected=Request.Form["rbGhataKhadamat"].Split(new char[]{','});
Page.ClientScript.RegisterStartupScript(GetType(), "OK", "OK(" + "'" + strSelected[0] + "','" + strSelected[1] + "','" + strSelected[2] + "'"+");", true);
}
it doesnt call OK function.
id didnt used onclientclick event cause i must pass the selected grid values.
thanks in advanced!
modified 17-Nov-12 4:50am.
|
|
|
|
|
I solved by adding <base target="_self" /> to of this (child) page.
my code is now this :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GridviewGhataKhadamat.aspx.cs"
Inherits="Tina.WebUI.WorkFlows.Forms.Khadamat.GridviewGhataKhadamat"%>
<!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">
<title></title>
<script type="text/javascript">
function Close() {
window.close();
}
function OK(Id,Name,Code) {
var vReturnValue = new Object();
vReturnValue.Id = Id;
vReturnValue.Name = Name;
vReturnValue.Code = Code;
window.returnValue = vReturnValue;
window.close();
}
</script>
<base target=_self>
</head>
<body >
<form id="form1" runat="server">
<div>
<%----%>
<asp:GridView ID="gvGhataKhadamat" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#CC9966" BorderStyle="Inset" BorderWidth="1px" CellPadding="4" Font-Names="Verdana">
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<Columns>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<input name="rbGhataKhadamat" type="radio" value="<%# Eval("Id") %>,<%# Eval("Name") %>,<%# Eval("Code") %>" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Id" HeaderText="ID" Visible="false" />
<asp:BoundField DataField="Code" HeaderText="<%$ Resources:Khadamat, Code %>" />
<asp:BoundField DataField="Name" HeaderText="<%$ Resources:Khadamat, Name %>" />
</Columns>
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
</asp:GridView>
</div>
<asp:Button runat="server" ID="btnOk" Text="<%$ Resources:Khadamat, ok %>" UseSubmitBehavior="false" OnClick="btnOk_Click"/>
<asp:Button runat="server" ID="btnCancel" Text="<%$ Resources:Khadamat, cancel %>"
OnClientClick="Close()" />
</form>
</body>
</html>
and bihind code is :
protected void Page_Load(object sender, EventArgs e)
{
DataTable dtGhataKhadamat = new DataTable();
string strGridViewType = Request.QueryString["gridname"];
if (strGridViewType == "Ghata")
{
dtGhataKhadamat = tblKhadamatBL.KalaViewSelectByCommandKhadamat("GroupKalaID=15");
gvGhataKhadamat.DataSource = dtGhataKhadamat;
gvGhataKhadamat.DataBind();
}
else if (strGridViewType == "Khadamat")
{
dtGhataKhadamat = tblKhadamatBL.KhadamatTypeSelectAllKhadamat();
gvGhataKhadamat.DataSource = dtGhataKhadamat;
gvGhataKhadamat.DataBind();
}
}
protected void btnOk_Click(object sender, EventArgs e)
{
string[] strSelected = Request.Form["rbGhataKhadamat"].Split(new char[] { ',' });
string jsCommand = "OK(" + "'" + strSelected[0] + "','" + strSelected[1] + "','" + strSelected[2] + "'" + ")";
Page.ClientScript.RegisterStartupScript(GetType(), "OK", jsCommand, true);
}
|
|
|
|