私の状況:
ASP.NETボタンに問題があり、ボタンをクリックしてもポストバックが発生しません。
ID「PurchaseBtn」のボタンがあります。このボタンをクリックすると、jQueryを使用して「PurchaseDiv」というパネルが開きます。
動作しないボタンは「PutInBasket」ボタンです。ボタンをクリックしても何も起こらず、確かにポストバックもありません。
OnClientClick ="returntrue;"を追加してみました 、その後、ポストバックが発生しますが、コードビハインドは実行されません。したがって、それも解決策ではありません。
コード
私は次のコードを持っています:
<asp:Button ID="PurchaseBtn" runat="server" Text="Køb" />
<asp:Panel ID="PurchaseDiv" runat="server" CssClass="Popup">
<asp:HyperLink id="PopupCloseLnk" runat="server" CssClass="popupClose">x</asp:HyperLink>
<h3>Køb <asp:Label ID="LinkTypeName" runat="server"></asp:Label></h3>
<p>Ønsket URL:<br />
<asp:TextBox ID="UrlBox" runat="server" Width="250"></asp:TextBox>
<asp:RequiredFieldValidator ID="UrlReq" runat="server" ControlToValidate="UrlBox" Text="*" ForeColor="Red"></asp:RequiredFieldValidator>
</p>
<p>Antal:<br />
<asp:Textbox ID="QuantityBox" runat="server"></asp:Textbox>
<asp:NumericUpDownExtender ID="QuantityExtender" runat="server"
Width="100"
TargetControlID="QuantityBox"
Minimum="1"
Maximum="200">
</asp:NumericUpDownExtender>
</p>
<br />
<p>Anchor tekster<br />
<asp:TextBox ID="AnchorTexts" runat="server" TextMode="MultiLine">
</asp:TextBox>
<asp:TextBoxWatermarkExtender ID="AnchorTextsExtender" runat="server" WatermarkCssClass="watermarked"
TargetControlID="AnchorTexts" WatermarkText="Ikke påkrævet at udfylde" />
</p>
<asp:Button ID="PutInBasket" runat="server" Text="Put i kurv"
onclick="PutInBasket_Click" />
</asp:Panel>
<asp:Panel id="bgPopup" runat="server" CssClass="bgPopup"></asp:Panel>
そして次のjQuery:
<script type="text/javascript">
function loadPopup() {
//loads popup only if it is disabled
if ($('#<%=bgPopup.ClientID %>').data("state") == 0) {
$('#<%=bgPopup.ClientID %>').css({
"opacity": "0.7"
});
$('#<%=bgPopup.ClientID %>').fadeIn("medium");
$('#<%=PurchaseDiv.ClientID%>').fadeIn("medium");
$('#<%=bgPopup.ClientID %>').data("state", 1);
}
}
function disablePopup() {
if ($('#<%=bgPopup.ClientID %>').data("state") == 1) {
$('#<%=bgPopup.ClientID %>').fadeOut("medium");
$('#<%=PurchaseDiv.ClientID %>').fadeOut("medium");
$('#<%=bgPopup.ClientID %>').data("state", 0);
}
}
function centerPopup() {
var winw = $(window).width();
var winh = $(window).height();
var popw = $('#<%=PurchaseDiv.ClientID%>').width();
var poph = $('#<%=PurchaseDiv.ClientID%>').height();
$('#<%=PurchaseDiv.ClientID%>').css({
"position": "absolute",
"top": winh / 2 - poph / 2,
"left": winw / 2 - popw / 2
});
//IE6
$('#<%=bgPopup.ClientID %>').css({
"height": winh
});
}
$(document).ready(function () {
var mouse_is_inside = true;
$('#<%=PurchaseDiv.ClientID%>').hover(function () {
mouse_is_inside = true;
}, function () {
mouse_is_inside = false;
});
$("body").mouseup(function () {
if (!mouse_is_inside) {
disablePopup();
}
});
$('#<%=bgPopup.ClientID %>').data("state", 0);
$('#<%=PurchaseBtn.ClientID%>').click(function () {
centerPopup();
loadPopup();
});
$('#<%=PopupCloseLnk.ClientID %>').click(function () {
disablePopup();
});
$(document).keypress(function (e) {
if (e.keyCode == 27) {
disablePopup();
}
});
});
$(window).resize(function () {
centerPopup();
});
</script>
PutInBasketのコードビハインド
protected void PutInBasket_Click(object sender, EventArgs e) {
var purchase = BuildPurchase();
if(SessionManager.Purchases = null)
{
SessionManager.Purchases = new Purchase();
}
SessionManager.Purchases.AddPurchase(purchase);
RedirectManager.RedirectToShoppingBasket();}
HTMLでのマークアップ
<body>
<form method="post" action="Default.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="ToolkitScriptManager1_HiddenField" id="ToolkitScriptManager1_HiddenField" value="" />
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTYyNDIzOTI1MA9kFgJmD2QWAgIDD2QWDAIDDw8WAh4EVGV4dAUMKzQ1IDMxNjkzNDQzZGQCBQ8PFgIeC05hdmlnYXRlVXJsBQt+L09tT3MuYXNweGRkAgcPDxYCHwEFDn4vS29udGFrdC5hc3B4ZGQCCQ9kFgICAQ9kFgJmDxQrAAIPFgQeC18hRGF0YUJvdW5kZx4LXyFJdGVtQ291bnQCAWRkFgJmD2QWAgIBD2QWAmYPZBYCZg9kFgICAQ9kFgJmD2QWAmYPZBYCAgEPZBYCAgEPZBYCZg9kFghmDw8WAh8ABQ1CbG9na29tbWVudGFyZGQCAg8PFgIfAAUJMjksMDAgREtLZGQCAw9kFgICAQ9kFgICAw8PFgIfAAUNQmxvZ2tvbW1lbnRhcmRkAgQPZBYCAgEPDxYCHwAFKTxoMz5CbG9na29tbWVudGFyPC9oMz5iZXNrcml2ZWxzZSBhZiBibG9nZGQCCw8PFgIfAQUVfi9TaG9wcGluZ0Jhc2tldC5hc3B4ZGQCEQ9kFgoCAQ8PFgIfAAUTVmkgbGV2ZXJlcmVyIGFsZHJpZ2RkAgMPDxYCHwAFGVRodWphdmVqIDUgMzY1MCDDmGxzdHlra2VkZAIFDw8WAh8ABQdEZW5tYXJrZGQCCQ8PFgIfAAUMKzQ1IDMxNjkzNDQzZGQCCw8PFgIfAAUIMzQwMTM0MzhkZBgBBTRjdGwwMCRDb250ZW50UGxhY2VIb2xkZXIxJExpbmtzT3ZlcnZpZXcxJFByb2R1Y3RWaWV3DxQrAA5kZGQCA2RkZBQrAAFkAgFkZGRmAv////8PZD4YJWAdCa4KWNlaqCdSdPimn/D66/4Q39o0LzMUuiwk" />
</div>
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
<script src="/Client/WebResource.axd?d=OQImHOjbC8T9DkQAEsUir2SbTKmI8ZHSylTzW2Dc_v2PQCtNyS3HT4PJHErgeJx_VIraTiSecUhyJJm6dR8vatqP9g2Jc9yVKn3Q2ZgQiXU1&t=634685062757536216" type="text/javascript"></script>
<script src="/Client/ScriptResource.axd?d=wBt9eolujUDT1pwJVXfdkbPt3q6kho05pcKqWgTyNHdCTBOV8kYqK-XubOHF3qVWllTVqvuXXPnc41-lbrsFIHVDLKwJaNX7FkZ6ir8UIWzkCnSjfN0j1OMJiUgdaTA6xM6LXQF8MVlGpJHoPSvyxzKcilhfqsLP0c-fl2Lt0Mc1&t=150492e7" type="text/javascript"></script>
<script src="/Client/ScriptResource.axd?d=UP06sTpweppdnIadbdu8iZGs1AZaASdPaGRzQUw527ewVZ7zBazaEOYbnh_jf7YtCQMLSB2Hvr25yeSR5oCk-0zjwGmQ19sQWp6ex8TA4DnvWtZYtv58zaC8COurXpj3OrICAaySLoXeOt0r12dnpQ2&t=fffffffffd88dfc4" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.');
//]]>
</script>
<script src="/Client/ScriptResource.axd?d=vFgiOpDr8tKXR2y_94kZYrOfpgLUdhZXjzsbRg0Z4ZyFIo0hRl2M_hrQvnzhD4-5xANDsYczXpx031bvwW78vpfjOADpPKmQJYO45cCutF_q9BnxFi6v1fdC4snZUAlirCG8fNtXsSXIc2nxdEeIEQ2&t=fffffffffd88dfc4" type="text/javascript"></script>
<script src="/Client/Default.aspx?_TSM_HiddenField_=ToolkitScriptManager1_HiddenField&_TSM_CombinedScripts_=%3b%3bAjaxControlToolkit%2c+Version%3d4.1.60623.0%2c+Culture%3dneutral%2c+PublicKeyToken%3d28f01b0e84b6d53e%3aen-US%3a187c1d17-2715-476f-9eeb-4fd46e2849ea%3ade1feab2%3af9cec9bc%3aee910bbe%3a35576c48" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function WebForm_OnSubmit() {
null;if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
return true;
}
//]]>
</script>
<div class="aspNetHidden">
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBwKRoIbQCQLNv7y8AQL3ypGNDwLD/ouZAwKcyMzCBgKB+6+CBQL7o4C5BYHZ9ukNCXioJ4HgOg0byK4OWNHAc/xaAvgFOzmITJSc" />
</div>
<script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ctl00$ToolkitScriptManager1', 'form1', [], [], [], 90, 'ctl00');
//]]>
</script>
<div class="WrapperContent">
<div class="Maincontent">
<table>
<tr>
<td class="MainContentTd">
<table id="ContentPlaceHolder1_LinksOverview1_ProductView_tblProducts" cellpadding="2" cellspacing="10">
<tr id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_productRow">
<td id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_Td1_0" style="vertical-align:top; text-align:left; height:100%; padding:8px; width:205px;">
<div id="sub">
<div id="category">
<br />
<div id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_PutProductHereDiv_0">
<script type="text/javascript">
$(document).ready(function () {
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_questionMark_0').mouseover(function (e) {
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_HintDiv_0').show();
});
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_questionMark_0').mouseleave(function (e) {
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_HintDiv_0').hide();
});
});
</script>
<h3>
<span id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_LinkTypeDescription_0">Blogkommentar</span>
<span id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_questionMark_0" class="questionMarkLayout">(?)</span></h3>
<table>
<tr>
<td>
<span id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PriceLbl_0">29,00 DKK</span>
</td>
<td>
<script type="text/javascript">
function loadPopup() {
//loads popup only if it is disabled
if ($('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_bgPopup_0').data("state") == 0) {
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_bgPopup_0').css({
"opacity": "0.7"
});
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_bgPopup_0').fadeIn("medium");
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_PurchaseDiv_0').fadeIn("medium");
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_bgPopup_0').data("state", 1);
}
}
function disablePopup() {
if ($('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_bgPopup_0').data("state") == 1) {
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_bgPopup_0').fadeOut("medium");
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_PurchaseDiv_0').fadeOut("medium");
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_bgPopup_0').data("state", 0);
}
}
function centerPopup() {
var winw = $(window).width();
var winh = $(window).height();
var popw = $('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_PurchaseDiv_0').width();
var poph = $('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_PurchaseDiv_0').height();
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_PurchaseDiv_0').css({
"position": "absolute",
"top": winh / 2 - poph / 2,
"left": winw / 2 - popw / 2
});
//IE6
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_bgPopup_0').css({
"height": winh
});
}
$(document).ready(function () {
var mouse_is_inside = true;
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_PurchaseDiv_0').hover(function () {
mouse_is_inside = true;
}, function () {
mouse_is_inside = false;
});
$("body").mouseup(function () {
if (!mouse_is_inside) {
disablePopup();
}
});
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_bgPopup_0').data("state", 0);
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_PurchaseBtn_0').click(function () {
centerPopup();
loadPopup();
});
$('#ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_PopupCloseLnk_0').click(function () {
disablePopup();
});
$(document).keypress(function (e) {
if (e.keyCode == 27) {
disablePopup();
}
});
});
$(window).resize(function () {
centerPopup();
});
</script>
<input type="submit" name="ctl00$ContentPlaceHolder1$LinksOverview1$ProductView$ctrl0$ctl01$ctl00$PurchaseButton1$PurchaseBtn" value="Køb" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$LinksOverview1$ProductView$ctrl0$ctl01$ctl00$PurchaseButton1$PurchaseBtn", "", true, "", "", false, false))" id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_PurchaseBtn_0" />
<div id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_PurchaseDiv_0" class="Popup">
<a id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_PopupCloseLnk_0" class="popupClose">x</a>
<h3>Køb <span id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_LinkTypeName_0">Blogkommentar</span></h3>
<p>Ønsket URL:<br />
<input name="ctl00$ContentPlaceHolder1$LinksOverview1$ProductView$ctrl0$ctl01$ctl00$PurchaseButton1$UrlBox" type="text" id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_UrlBox_0" style="width:250px;" />
<span id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_UrlReq_0" style="color:Red;visibility:hidden;">*</span>
</p>
<p>Antal:<br />
<input name="ctl00$ContentPlaceHolder1$LinksOverview1$ProductView$ctrl0$ctl01$ctl00$PurchaseButton1$QuantityBox" type="text" id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_QuantityBox_0" />
</p>
<br />
<p>Anchor tekster<br />
<textarea name="ctl00$ContentPlaceHolder1$LinksOverview1$ProductView$ctrl0$ctl01$ctl00$PurchaseButton1$AnchorTexts" rows="2" cols="20" id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_AnchorTexts_0">
</textarea>
<input type="hidden" name="ctl00$ContentPlaceHolder1$LinksOverview1$ProductView$ctrl0$ctl01$ctl00$PurchaseButton1$AnchorTextsExtender_ClientState" id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_AnchorTextsExtender_ClientState_0" />
</p>
<input type="submit" name="ctl00$ContentPlaceHolder1$LinksOverview1$ProductView$ctrl0$ctl01$ctl00$PurchaseButton1$PutInBasket" value="Put i kurv" id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_PutInBasket_0" />
</div>
<div id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_bgPopup_0" class="bgPopup">
</div>
</td>
</tr>
</table>
<br />
<div id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_HintDiv_0" class="HintDiv">
<span id="ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_DescriptionLbl_0"><h3>Blogkommentar</h3>beskrivelse af blog</span>
</div>
</div>
<br />
</div>
</td>
</tr>
</table>
</td>
<td class="RightContentTd">
<br />
<br />
</td>
</tr>
</table>
</div>
</div>
</div>
<script type="text/javascript">
//<![CDATA[
var Page_Validators = new Array(document.getElementById("ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_UrlReq_0"));
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
var ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_UrlReq_0 = document.all ? document.all["ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_UrlReq_0"] : document.getElementById("ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_UrlReq_0");
ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_UrlReq_0.controltovalidate = "ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_UrlBox_0";
ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_UrlReq_0.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_UrlReq_0.initialvalue = "";
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
(function() {var fn = function() {$get("ToolkitScriptManager1_HiddenField").value = '';Sys.Application.remove_init(fn);};Sys.Application.add_init(fn);})();
var Page_ValidationActive = false;
if (typeof(ValidatorOnLoad) == "function") {
ValidatorOnLoad();
}
function ValidatorOnSubmit() {
if (Page_ValidationActive) {
return ValidatorCommonOnSubmit();
}
else {
return true;
}
}
document.getElementById('ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_UrlReq_0').dispose = function() {
Array.remove(Page_Validators, document.getElementById('ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_UrlReq_0'));
}
Sys.Application.add_init(function() {
$create(Sys.Extended.UI.NumericUpDownBehavior, {"Maximum":200,"Minimum":1,"RefValues":"","ServiceDownMethod":"","ServiceDownPath":"/Client/Default.aspx","ServiceUpMethod":"","Tag":"","TargetButtonDownID":"","TargetButtonUpID":"","Width":100,"id":"ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_QuantityExtender_0"}, null, null, $get("ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_QuantityBox_0"));
});
Sys.Application.add_init(function() {
$create(Sys.Extended.UI.TextBoxWatermarkBehavior, {"ClientStateFieldID":"ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_AnchorTextsExtender_ClientState_0","WatermarkCssClass":"watermarked","WatermarkText":"Ikke påkrævet at udfylde","id":"ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_AnchorTextsExtender_0"}, null, null, $get("ContentPlaceHolder1_LinksOverview1_ProductView_ctrl0_ctl00_0_PurchaseButton1_0_AnchorTexts_0"));
});
//]]>
</script>
</form>
</body>