gpt4 book ai didi

javascript - 无法从 CodeBehind 调用 JavaScript 函数

转载 作者:行者123 更新时间:2023-12-02 23:10:23 25 4
gpt4 key购买 nike

我有 gridView,如果用户单击按钮,我想将其信息提供给弹出窗口。

这是打开和关闭弹出窗口的 JavaScript

<script type="text/javascript">
function ShowModalPopup() {
$find("mpe").show();
return false;
}
function HideModalPopup() {
$find("mpe").hide();
return false;
}

这是我的按钮

<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ImageUrl="~/Images/shopping.png" runat="server" ToolTip="Shopping" Width="20px" Height="20px" OnClick="makePurchaseOrder" />
</ItemTemplate>
</asp:TemplateField>

这是我调用按钮时发生的情况

    protected void makePurchaseOrder(object sender, EventArgs e)
{
ImageButton btn = (ImageButton)sender;
GridViewRow gvr = (GridViewRow)btn.NamingContainer;
int rowindex = gvr.RowIndex;
var idrow = (Control)sender;
GridViewRow row = (GridViewRow)idrow.NamingContainer;

componenteID = Convert.ToInt32(gvInventario.DataKeys[row.RowIndex].Values[0]);
proveedor_id = Convert.ToInt32(gvInventario.DataKeys[row.RowIndex].Values[2]);
Page.ClientScript.RegisterStartupScript(this.GetType(), "OpenPopupClick", "ShowModalPopup();", false);
}

这就是我的模态弹出窗口的样子

<asp:LinkButton ID="lnkDummy" runat="server"></asp:LinkButton>
<cc1:ModalPopupExtender ID="ModalPopupExtender1" BehaviorID="mpe" runat="server"
PopupControlID="pnlPopup" TargetControlID="lnkDummy" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlPopup" runat="server" style="display: none">
<div >
<div class="modal-content">
<asp:Button ID="btnHide" runat="server" OnClientClick="return HideModalPopup()" />
<a class="close" href="#" >&times;</a>
<h2>Here i am</h2>
<div class="content">
<asp:Label ID="Label17" runat="server" Text="Comprar" CssClass="second-menu-title"></asp:Label>
<br/>
<b><asp:Label ID="Label18" runat="server" Text="Proveedor: "></asp:Label></b>
<asp:Label ID="Label19" runat="server" Text=""></asp:Label>
<br/>
<b><asp:Label ID="Label20" runat="server" Text="Tipo: "></asp:Label></b>
<asp:Label ID="Label21" runat="server" Text=""></asp:Label>
<asp:Label ID="Label22" runat="server" Text=""></asp:Label>
<br/>
<b><asp:Label ID="Label23" runat="server" Text="Cantidad pedida: "></asp:Label></b>
<asp:TextBox width="50px" ID="TextBox2" runat="server" TextMode="Number" min="0" step="1" Value="0"></asp:TextBox>
<br/>
</div>
</div>
</div>
</asp:Panel>

问题是点击按钮时没有出现模式弹出窗口。我不确定为什么。任何帮助将不胜感激。

最佳答案

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>

<script type="text/javascript">
function ShowModalPopup() {
$('#<%= pnlPopup.ClientID %>').toggle();
}

function HideModalPopup() {
$('#<%= pnlPopup.ClientID %>').toggle();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:GridView ID="gvTest" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ImageUrl="~/Images/system/RightArrow.png" runat="server" OnClick="Unnamed_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

<asp:Panel ID="pnlPopup" runat="server" style="display:none;">
<asp:ImageButton ID="btnTest" ImageUrl="~/Images/system/RightArrow.png" runat="server" OnClientClick="HideModalPopup(); return false;" />
<p>Content Goes here</p>
</asp:Panel>

</div>
</form>
</body>
</html>
public partial class _testPWforSO :  System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
int rowcount = 0;
Collection<Product> products = InternalProduct.FindAll(0, 10, ref rowcount);
gvTest.DataSource = products;
gvTest.DataBind();
}
}

protected void Unnamed_Click(object sender, ImageClickEventArgs e)
{
// code to find out which one was clicked
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "OpenPopupClick", "ShowModalPopup()", true);
}
}

关于javascript - 无法从 CodeBehind 调用 JavaScript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57397377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com