[英]Dynamically added Link Button doesn't fire the on click event on the first click - C#
[英]MasterPage button click event doesn't fire on the first click but on the second click
嗨,謝謝您的幫助。 這是我的問題:
這是發生了什么:
我希望MasterPage的“保存”按鈕單擊事件能夠觸發,但它永遠不會觸發! 觸發主頁面textchange(SumAll())事件,但不會觸發MasterPage click事件。
如果我再次單擊MasterPage的“保存”按鈕,則MasterPage單擊事件將成功觸發,但是,當然不會發生Maintext更改事件。 當我只單擊MasterPage的“保存”按鈕而不在主頁上進行任何更改時,情況也是如此。
這是我的代碼示例。 主頁textchanged事件:
protected void SumTheAmounts(object sender, EventArgs e)
{
Decimal lease = 0.00M;
Decimal securityDeposit = 0.00M;
Decimal miscellanious = 0.00M;
Decimal sumTotal = 0.00M;
Decimal.TryParse(txtMiscellaneousAmount.Text, out miscellanious);
Decimal.TryParse(txtSecurityDepositAmount.Text, out securityDeposit);
Decimal.TryParse(txtLeaseAmount.Text, out lease);
sumTotal = miscellanious + securityDeposit + lease;
txtAmount.Text = sumTotal.ToString();
// Set focus to the next textbox
TextBox tb = (TextBox)sender;
switch (tb.ID)
{
case "txtLeaseAmount":
txtSecurityDepositAmount.Focus();
break;
case "txtSecurityDepositAmount":
txtMiscellaneousAmount.Focus();
break;
case "txtMiscellaneousAmount":
txtMiscellaneousAmount.Focus(); // Send back to the same. .
break;
default:
break;
}
}
和我的MasterPage的“保存”按鈕單擊事件:
protected void btnSave_Click(object sender, EventArgs e)
{
// Save every little thing...
switch (ContentPageLoaded)
{
case "CheckRequest":
((CheckRequest)ContentMain.Page).UpdateMe();
break;
case "PicturesLoad":
((PicturesLoad)ContentMain.Page).UpdateMe();
break;
default:
break;
}
}
標記:
<asp:Panel ID="pnlSave" CssClass="ButtonClass" runat="server">
<asp:Button ID="btnSave" style="width:160px; font-size:small; position:relative; color:Blue; top: 0px; left: 0px;" runat="server" Text="Save" onclick="btnSave_Click" CausesValidation="False" />
</asp:Panel>
PageLoad:
if (!IsPostBack)
{
Button saveButton = (Button)Master.FindControl("btnSave");
branchName = (string)Session["BranchName"];
branchLegalData = new Classes.BranchLegalData();
if ((branchName != null) && (branchName.Length > 0))
{
FillThisPageData();
}
}
else { }
Master.ContentPageLoaded = "CheckRequest";
任何幫助都非常感謝! 謝謝
這是黑暗中的鏡頭,但是請嘗試為所有文本框設置autopostback =“ false”。 我懷疑可能發生的情況是,當您將注意力集中在文本框上時,您將觸發兩次回發,然后單擊一次。
僅當將autopostback設置為true時,才會發生這種情況。
感謝大家!
在文本框上設置autopostback =“ false”可行! 我認為發生的事情是,使用autopostback =“ true”時,文本框將觸發它自己的文本更改事件,並且由於某種原因,之后不會觸發MasterPage按鈕單擊事件? 有人可以告訴我為什么觸發文本框事件而不觸發按鈕事件嗎???
無論如何,此問題已得到解決,我非常感謝您的投入...你們真棒!
史蒂夫
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.