2011-06-10 48 views
0

提交後什麼也沒有發生:在Windows Server 2008和Visual Studio 2010和Windows Vista與Visual Studio 2008很奇怪的問題:在測試的ASPX網頁

以下unusuall的問題已經顯現。

我有一個用戶控件和網站控制將顯示。 如果即時檢查控件的單選按鈕,並點擊提交,這也是在裏面ctrol沒有發生。沒有要求服務器,只是沉默。

一切看起來不錯,標準,但我無法找到問題。請幫忙,因爲它煩人!

usercontrol.ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="EmployeeCategorizationControl.ascx.cs" 
    Inherits="EmployeeCategorizationControl.EmployeeCategorizationControl" %> 

<div id="categorizationOfEmployee"> 
<div>Categorization od Employee</div><br /> 
    <div id="firstCategory"> 
     <div style="float: left; width: 250px;"> 
      Is not a permanent employee</div> 
     <div> 
      <asp:RadioButtonList ID="YesNoIsNotPermanentEmployee" runat="server" RepeatDirection="Horizontal"> 
       <asp:ListItem Text="Yes" Value="1"></asp:ListItem> 
       <asp:ListItem Text="No" Value="0"></asp:ListItem> 
      </asp:RadioButtonList> 
     </div> 
    </div> 
    <div id="secondCategory"> 
     <div style="float: left; width: 250px;"> 
      Is a fixed-term employee</div> 
     <div> 
      <asp:RadioButtonList ID="YesNoIsFixedTermEmployee" runat="server" RepeatDirection="Horizontal"> 
       <asp:ListItem Text="Yes" Value="1"></asp:ListItem> 
       <asp:ListItem Text="No" Value="0"></asp:ListItem> 
      </asp:RadioButtonList> 
     </div> 
    </div> 
    <div id="thirdCategory"> 
     <div style="float: left; width: 250px;"> 
      No external recruit</div> 
     <div> 
      <asp:RadioButtonList ID="YesNoExternalRecruit" runat="server" RepeatDirection="Horizontal"> 
       <asp:ListItem Text="Yes" Value="1"></asp:ListItem> 
       <asp:ListItem Text="No" Value="0"></asp:ListItem> 
      </asp:RadioButtonList> 
     </div> 
    </div> 
    <div id="btCreate" style="margin-left: 200px; margin-top: 10px;"> 
     <asp:Button runat="server" Text="Create Checklist" ID="btCreateChecklist" /> 
    </div> 
</div> 

usercontrol.ascx.cs:

protected void Page_Load(object sender, EventArgs e) 
     { 
      btCreateChecklist.Click += new EventHandler(btCreateChecklist_Click); 

     } 

void btCreateChecklist_Click(object sender, EventArgs e) 
     { 
      ValueOfIsNotPermanentEmployee = YesNoIsNotPermanentEmployee.Text; 
      ValueOfIsFixedTermEmployee = YesNoIsFixedTermEmployee.Text; 
      ValueOfNoExternalRecruit = YesNoExternalRecruit.Text; 
      UserCategoryID = ValueOfIsNotPermanentEmployee + ValueOfIsFixedTermEmployee + ValueOfNoExternalRecruit; 
     } 

的Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="EmployeeCategorizationControl._Default" %> 
<%@ Register TagPrefix="UserControl" TagName="EmployeeCategorizationControl" Src="~/EmployeeCategorizationControl.ascx" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
    <UserControl:EmployeeCategorizationControl runat="server" /> 
    </div> 
    </form> 
</body> 
</html> 
+0

無法重現問題(VS2008,.NET3.5,ASP.NET開發服務器)。這是唯一的頁面/用戶控件無法回發? – mika 2011-06-10 10:55:51

+0

你可以試試這個: 2GDev 2011-06-10 11:02:41

回答

1

這段代碼看起來像我看到的那樣完美。我已經將你的代碼移植到本地應用程序中了(改變命名空間以消除編譯錯誤),並且它回傳得很好。然而,除了設置幾個變量(你不能解釋他們做什麼或涉及到什麼)之外,你的事件不會做任何事情。你確定它沒有執行回帖嗎?此頁面足夠小,以至於回發可能甚至不會導致屏幕閃爍(因爲沒有實際的操作正在進行)。您應該在事件方法中添加一些可見的操作,例如更改標籤的文本或按鈕的BackColor

0

如果你有AutoEventWireup="true"沒有必要:

btCreateChecklist.Click += new EventHandler(btCreateChecklist_Click); 

將其設置爲false或刪除上述語句。

+0

我在default.aspx中使用了control.ascx – 2011-06-10 10:44:08

+0

閱讀關於它是如何工作的。它會自動掛上事件名稱。 – leppie 2011-06-10 10:45:44

+0

'AutoEventWireup'僅適用於頁面事件。 btCreateChecklist.Click不是頁面事件。它也不會對此行爲負責。如果這是問題,他的代碼將生成2個點擊事件。 – 2011-06-10 10:59:38