大家好我使用 javascript 通过使用链接按钮的 ID 来根据点击的链接按钮制作一些事件我的asp页面的代码
<asp:LinkButton ID="Tlbr_Item_New" runat="server" CssClass="button_big">Tlbr_Item_New</asp:LinkButton>
<asp:LinkButton ID="Tlbr_Item_Save" runat="server" CssClass="button_big" OnClientClick="return ToolBarClickItem(this);" >Tlbr_Item_Save</asp:LinkButton>
<asp:LinkButton ID="Tlbr_Item_delete" runat="server" CssClass="button_big" OnClientClick="return ToolBarClickItem(this);" >Tlbr_Item_delete</asp:LinkButton>
<asp:LinkButton ID="Tlbr_Item_Undo" runat="server" CssClass="button_big" OnClientClick="return ToolBarClickItem(this);" >Tlbr_Item_Undo</asp:LinkButton>
<asp:LinkButton ID="Tlbr_Item_Clear" runat="server" CssClass="button_big" OnClientClick="return ToolBarClickItem(this);" >Tlbr_Item_Clear</asp:LinkButton>
<asp:LinkButton ID="Tlbr_Item_Search" runat="server" CssClass="button_big" OnClientClick="return ToolBarClickItem(this);" >Tlbr_Item_Search</asp:LinkButton>
<asp:LinkButton ID="Tlbr_Item_Print" runat="server" CssClass="button_big" OnClientClick="return ToolBarClickItem(this);" >Tlbr_Item_Print</asp:LinkButton>
<asp:LinkButton ID="Tlbr_Item_Close" runat="server" CssClass="button_big" OnClientClick="return ToolBarClickItem(this);" >Tlbr_Item_Close</asp:LinkButton>
,这是我的javascript函数
function ToolBarClickItem(Item) {
window.style = "cursor:hand;";
var bRes = true;
var sMessage = "";
var ItemID = "";
if (typeof Item == 'object')
ItemID = Item.id;
else
ItemID = Item;
switch (ItemID) {
case "Tlbr_Item_New":
if (NewButtonURL != "")
bRes = eval(NewButtonURL);
break;
case "Tlbr_Item_Save":
if (SaveButtonURL != "")
bRes = eval(SaveButtonURL);
if (bRes == true) {
if (IsAnyRequiredEmpty(document.forms[0])) {
window.alert(ErrorEmptyNotAllowed);
bRes = false;
}
else
sMessage = WarnMessageArray[ItemID];
}
break;
case "Tlbr_Item_delete":
if (DeleteButtonURL != "")
bRes = eval(DeleteButtonURL);
sMessage = WarnMessageArray[ItemID];
break;
case "Tlbr_Item_Undo":
if (UndoButtonURL != "")
bRes = eval(UndoButtonURL);
sMessage = WarnMessageArray[ItemID];
break;
case "Tlbr_Item_Clear":
if (ClearButtonURL != "")
bRes = eval(ClearButtonURL);
break;
case "Tlbr_Item_Search":
if (SearchButtonURL != "")
bRes = eval(SearchButtonURL);
break;
case "Tlbr_Item_Print":
if (PrintButtonURL != "")
bRes = eval(PrintButtonURL);
if (bRes == true && bFreeSearch == false)
if (IsAnyPrimaryEmpty(document.forms[0])) {
window.alert('No Record To Print');
bRes = false;
}
else
CustomPrint(PrintURL);
break;
case "Tlbr_Item_Close":
if (confirm('سيتم إغلاق الشاشة؟'))
window.close();
bRes = false;
break;
}
if (sMessage != "" && bRes == true)
bRes = ShowAskMessage(WarnMessageArray[ItemID]);
return bRes;
}
当我在本地IIS上测试它时效果很好
但是当我把它丢在我的服务器上时就是somee.com 链接按钮控制对ctloo_Tlbr_Item_Save的更改,但它不起作用 所以我不知道问题和解决方案是什么
答案 0 :(得分:2)
您可以使用ClientIdMode=Static
。
您可以通过在网站的ClientIDMode
文件中设置pages元素,为网站中的所有网页设置Web.config
值。您可以在@Page directive
中为页面设置ClientIDMode值。使用.NET4,您甚至可以通过Control.ClientIdMode
将其设置为控件。
页面的ClientIDMode的默认值为Predictable
。控件的ClientIDMode的默认值为Inherit
。
但是,您也可以通过ClientID
:$("#<%= Tlbr_Item_Save.ClientID %>")
答案 1 :(得分:1)
试试这个
switch (ItemID) {
case '<%= Tlbr_Item_New.ClientID %>':
//Your code
break;
case '<%= Tlbr_Item_Save.ClientID %>':
//Your code
break;
case '<%= Tlbr_Item_delete.ClientID %>':
//Your code
break;
case '<%= Tlbr_Item_Undo.ClientID %>':
//Your code
break;
}