服务器端: protected void Search_Click(object sender, EventArgs e) { -6ren">
gpt4 book ai didi

c# - 在 C# 中停止服务器端函数

转载 作者:太空宇宙 更新时间:2023-11-03 13:42:55 26 4
gpt4 key购买 nike

我的代码:

<asp:LinkButton ID="Search" CssClass="button" runat="server" Text='<%$Resources:Strings,Search %>' OnClick="Search_Click"  />

服务器端:

protected void Search_Click(object sender, EventArgs e)
{
var script = "CheckIfItemSelected()";
ScriptManager.RegisterStartupScript(this, GetType(), "MyScript", script, true);
}

客户端:

function CheckIfItemSelected() {
var SalesmanSelectedItem = $find('<%= SalesmanGrid_grd.ClientID %>').get_masterTableView().get_selectedItems().length;
var ProductsSelectedItem = $find('<%= SalsemanProductsGrid_grd.ClientID %>').get_masterTableView().get_selectedItems().length;

if (SalesmanSelectedItem == 0 && ProductsSelectedItem == 0) {

$("#<%=ErrorMsg.ClientID %>").html("please select a salesman at least<br>please select a product at least");
return false;
}
if (SalesmanSelectedItem == 0) {
$("#<%=ErrorMsg.ClientID %>").html("please select a salesman at least");
return false ;
}
if (ProductsSelectedItem == 0) {
$("#<%=ErrorMsg.ClientID %>").html("please select a product at least");
return false;
}
$("#<%=ErrorMsg.ClientID %>").html("");
return true;
}

问题是如果我的客户端函数返回 false 我想停止服务器端函数继续我应该怎么做?

最佳答案

找到我的解决方案,希望对您有所帮助:

 protected void Search_Click(object sender, EventArgs e)
{
int SelectedSalesmans= SalesmanGrid_grd.SelectedItems.Count;
int SelectedProducts = SalsemanProductsGrid_grd.SelectedItems.Count;
if (SelectedSalesmans == 0)
{
var script = "DisplayErrorMsg(\"Please Choose a salesman AT least. \")";
ScriptManager.RegisterStartupScript(this, GetType(), "MyScript", script, true);
return;
}
if (SelectedProducts == 0)
{
var script = "DisplayErrorMsg(\"Please Choose a Product AT least. \")";
ScriptManager.RegisterStartupScript(this, GetType(), "MyScript", script, true);
return;
}
}

客户端:

function DisplayErrorMsg(msg) {
$("#<%=ErrorMsg.ClientID %>").html(msg);
}

关于c# - 在 C# 中停止服务器端函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16372058/

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