2009-03-31 9 views
1

私はウィザードコントロールを利用できると知っていますが、私が欲しいものはとても単純です。ここで深いところからどこを追い始めるのか分かりません。ユーザーが自分の名前とヒットを次に押すと、カレンダーコントロールが開始日に選択可能になります。私は開始日を緑色にすることができます。私は、彼らが[続行]ボタンを押すまで選択して欲しい。第1号は、彼らが日付なしで次に打つことができるということです。私はそれをキャッチしたい。問題2は、次に打つ前に何度も再選択できるということです。私は彼らにそれをできるようにして欲しい。彼らが次にヒットすると、次のヒットまで何度も何度も日付を選択して終了することができます。それから私は彼らに彼らのコシを確認してもらいたい。私はロジックがあまり単純ではないと思う...私が書いたコードはとても悪い。 StartDateStartPartとEndDateStartPartはちょうど精神的ちんぷんかんぷんなるので:(。でも、適切な修正は私の頭を傷つける。私は明らかに地上からこれを再考し、やり直しする必要がありますするつもりです。ASP.NETウィザードを設計する良い方法はありますか?

<script runat="server" enableviewstate="True"> 

DateTime begin; 
DateTime end; 
int iSelectedStart = 0; 
int iSelectedEnd = 0; 
int iPutName = 0; 

protected void Button1_Click(object sender, EventArgs e) 
{ 
    if (iPutName == 0) 
    { 
    Label1.Text = TextBox1.Text + " you will be slecting your start and end dates."; 
    LabelInstructions1.Text = "Please select a begin date and hit next"; 
    Calendar1.SelectionMode = System.Web.UI.WebControls.CalendarSelectionMode.Day; 
    iPutName = 1; 
    ViewState["iPutName"] = 1; 
    ViewState["Label1_Text"] = Label1.Text; 
    ViewState["LabelInstructions1_Text"] = LabelInstructions1.Text; 
    ViewState["Calendar1_SelectionMode"] = Calendar1.SelectionMode; 
    } 
    else 
    { 
    if (iSelectedStart <= 0) 
    { 
     LabelInstructions1.Text = "You have not selected a start date please do so."; 
    } 
    else if (iSelectedStart < 99) 
    { 
     iSelectedStart = 99; 
     Label1.Text = TextBox1.Text + " you will be slecting your start and end dates."; 
     LabelInstructions1.Text = "Please select an end date and hit confirm"; 
     ViewState["begin"] = begin; 
     ViewState["iSelectedStart"] = iSelectedStart; 
    } 
    else 
    { 
     if (iSelectedEnd = 0) 
     { 
     LabelInstructions1.Text = "You have not selected a start date please do so."; 
     } 
    } 

    } 
} 


protected void Calendar1_SelectionChanged(object sender, EventArgs e) 
{ 
    if (iSelectedStart < 99) 
    { 
    iSelectedStart++; 
    begin = Calendar1.SelectedDate; 
    ViewState["iSelectedStart"] = iSelectedStart; 
    ViewState["begin"] = begin; 
    } 
    else 
    { 
    if (begin == Calendar1.SelectedDate) 
    { 
     LabelInstructions1.Text = "Error you cannot select the same start and end date"; 
     LabelInstructions1.ForeColor = System.Drawing.Color.Red; 
    } 
    else 
    { 
     end = Calendar1.SelectedDate; 
     iSelectedEnd = 0; 
     ViewState["end"] = end; 
    } 
    } 
} 

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e) 
{ 
    if (e.Day.Date == begin) 
    { 
    e.Cell.BackColor = System.Drawing.Color.Green; 
    } 
    if (e.Day.Date == end) 
    { 
    e.Cell.BackColor = System.Drawing.Color.Red; 
    } 
} 

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (ViewState["iPutName"] != null) 
    iPutName = (int)ViewState["iPutName"]; 

    if (ViewState["Label1_Text"] != null) 
    Label1.Text = ViewState["Label1_Text"].ToString(); 

    if (ViewState["LabelInstructions1_Text"] != null) 
    LabelInstructions1.Text = ViewState["LabelInstructions1_Text"].ToString(); 

    if (ViewState["Calendar1_SelectionMode"] != null) 
    Calendar1.SelectionMode = (CalendarSelectionMode) ViewState["Calendar1_SelectionMode"]; 

    if (ViewState["begin"] != null) 
    begin = (DateTime)ViewState["begin"]; 

    if (ViewState["end"] != null) 
    end = (DateTime)ViewState["end"]; 
} 
+0

asp.netタグを追加してください: – JoshJordan

+0

アドバイスいただきありがとうございます! – ojblass

+0

私は自分の答えを持っているだけで閉じるべきですか? – ojblass

答えて

1

AJAXを使いたくない場合は、Webフォームでこのようなことを行う伝統的な方法は、ウィザードの各ページ/フォームにパネルコントロールを使用して、さまざまなパネルをポストバック。それはAJAXのアプローチほど楽しくないかクールではありませんが、単純な小さなウィザードであれば、これをすばやく簡単に行うことができます。ページビューステートは、あなたが、あなたが非表示ととして、あなたのビジネスロジックを実装するためにコードビハインドにアクセスすることができ、あなたのコントロールの値を管理します

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PanelWizard._Default" %> 

<!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>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:Panel ID="wizForm1" runat="server" Height="50px" Width="125px"> 
      <asp:TextBox ID="txtName" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox></asp:Panel> 

    </div> 
     <asp:Panel ID="wizForm2" runat="server" Height="50px" Width="125px" Visible="False"> 
      <asp:Calendar ID="calStart" runat="server"></asp:Calendar> 
     </asp:Panel> 
     <asp:Button ID="btnContinue" runat="server" OnClick="btnContinue_Click" Text="Continue" /> 
    </form> 
</body> 
</html> 

Webフォームは、次のようになりますパネルを明らかにする。例:

namespace PanelWizard 
{ 
    public partial class _Default : System.Web.UI.Page 
    { 
     protected void btnContinue_Click(object sender, EventArgs e) 
     { 
      // validate controls according to business logic 
      //... 

      // Hide and reveal panels based on the currently visible panel. 
      if (wizForm1.Visible) 
      { 
       wizForm1.Visible = false; 
       wizForm2.Visible = true; 
      } 
      else if (wizForm2.Visible) 
      { 
       // and so on... 
      } 
     } 
    } 
} 
+0

良いこと...私が使用する解決策... – ojblass

0

あなたが使用する必要がありますように見えますjavacript/ajaxを使用して、ウィザードの直感的なUIを作成することができます。DOMエレメントの学習と操作が簡単なJqueryをお勧めします。

0

多くのことを考えた後、可能な限りすべての図を示した有限状態マシンさらに、良い名前の選択と、学習としての執筆ではないことがおそらく必要である。

関連する問題