在MasterPage中以AutoEventWireup = true運行。我無法改變這一點。 按鈕在數據庫中插入新記錄。
當按鈕命中時,插入兩條記錄。按鈕觸發兩次 - 在數據庫中插入2條記錄
<asp:Button ID="AddLab" Text="Add Lab" OnClick="AddLab_OnClick" CssClass="btn" runat="server" />
PageDirective:
AutoEventWireup="true" <- I have tried removing this, setting to false.
pageLoad的/在PreRender秀給你看這裏什麼都不做而使用按鈕:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DbDataReader ddrGrp = rdoGroups();
if (ddrGrp.HasRows)
{
rdoGroup.DataSource = ddrGrp;
rdoGroup.DataBind();
}
ddrGrp.Close();
// preset filter by lab to true
CheckBox FiltLabs = (CheckBox)CommonUI.FindCtrlRecursive(this.Master, "FiltLabs");
FiltLabs.Checked = true;
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
// nothing yet
rdoLabs.Items.Clear();
DbDataReader ddrLab = rdoUserLabs();
if (ddrLab.HasRows)
{
rdoLabs.DataSource = ddrLab;
rdoLabs.DataBind();
if (CommonUI.strTest((string)Session["rdoLabs"]))
{
if (Convert.ToInt32(Session["rdoLabs"]) > 0)
{
rdoLabs.SelectedValue = (string)Session["rdoLabs"];
}
}
}
ddrLab.Close();
// get group-lab mappings
cboGroupLab.Items.Clear();
DbDataReader ddrGroupLab = cboGroupLabsMap();
if (ddrGroupLab != null)
{
if (ddrGroupLab.HasRows)
{
cboGroupLab.DataSource = ddrGroupLab;
cboGroupLab.DataBind();
}
}
}
protected void AddLab_OnClick(object sender, EventArgs e)
{
LabAdmn labAdd = new LabAdmn();
TextBox txtLab = (TextBox)CommonUI.FindCtrlRecursive(this.Master, "txtLab");
CheckBox Active = (CheckBox)CommonUI.FindCtrlRecursive(this.Master, "cboLabActive");
string[] strArr = new string[] { "lab_id" };
labAdd.LabName = txtLab.Text;
labAdd.Active = (bool)Active.Checked;
// AddLab is where record is fired...see below...
Hashtable ht = labAdd.AddLab(labAdd, strArr);
ht = labAdd.AddLab(labAdd, strArr);
if (ht != null)
{
HiddenField hLabId = (HiddenField)CommonUI.FindCtrlRecursive(this.Master, "hLabId");
hLabId.Value = Convert.ToString(GetHTParm(ht, strArr[0]));
}
}
#endregion AddLab_OnClick
#region AddLab
public Hashtable AddLab(LabAdmn labAdmn, string[] colOutputNames)
{
DAL myDal = new DAL(DBType, DB);
Hashtable ht = new Hashtable();
DAL.Parameters[] parms = new DAL.Parameters[]
{
new DAL.Parameters("driver_id","A",ParameterDirection.Input),
new DAL.Parameters("lab_id",labAdmn.LabId,ParameterDirection.InputOutput),
new DAL.Parameters("active",labAdmn.Active,ParameterDirection.Input),
new DAL.Parameters("lab_name",labAdmn.LabName,ParameterDirection.Input)
};
CommandType cmdType = CommandType.StoredProcedure;
string cmdText = "asp_Labs_Admin";
ht = myDal.ExecuteQueryOutput(cmdType, cmdText, colOutputNames, parms, true);
return ht;
}
#endregion AddLab
我讀過的onclick和RUNAT造成雙重處理。如果我刪除runat,該按鈕將不會顯示,因爲它是一個服務器端按鈕。如果刪除了OnClick事件,則無論AutoEventWireup是true,false還是刪除,該事件都不會觸發。
你能格式化你的代碼的其餘部分,以及它很難看懂了嗎? Prerender也不是你想要進行數據綁定的地方。通常,在呈現給html之前,您可以使用該控件執行任何處理。 – WorldIsRound 2011-01-31 23:54:46
這聽起來很奇怪。但是,您是否可以檢查您的頁面上的圖片標籤,該圖片標籤不指向任何不存在的圖片或圖片。 – Phill 2011-02-01 00:09:35