M
Mike W
Hi
I have a problem with my webcontrol when I use in a MultiView.
I have a fairly simple webcontrol that consists of a Table with one row and
two cells, in the first Cell i have two TextBoxe's (one of which is hidden
from the User) and in the second Cell i have a HtmlButton.
The code is:
namespace WorkTech
{
[ParseChildren(false), ToolboxData("<{0}:SelectBox runat=server />")]
public class SelectBox : System.Web.UI.WebControls.WebControl,
INamingContainer
{
private TextBox m_Textbox;
private TextBox m_TextboxHiddenID;
private string m_Javascript = string.Empty;
public string JavaScript
{
get { return m_Javascript; }
set { m_Javascript = value; }
}
public string Text
{
get { return m_Textbox.Text; }
set { m_Textbox.Text = value; }
}
public Guid HiddenID
{
get { return Functions.ParseGuid(m_TextboxHiddenID.Text); }
set { m_TextboxHiddenID.Text = value.ToString(); }
}
protected override void CreateChildControls()
{
Controls.Clear();
m_Textbox = new TextBox();
m_TextboxHiddenID = new TextBox();
Table myTable = new Table();
m_Textbox.ID = "Textbox";
m_Textbox.CssClass = "TextBox";
if (Width.Type.ToString() == "Pixel" && Width.Value > 0)
{
int TextBoxWidth = Convert.ToInt32((Width.Value - 22));
m_Textbox.Width = Unit.Pixel(TextBoxWidth);
}
m_Textbox.Attributes.Add("readonly", "true");
m_TextboxHiddenID.ID = "HiddenID";
m_TextboxHiddenID.CssClass = "Hidden";
myTable.CellPadding = 0;
myTable.CellSpacing = 0;
TableRow TR = new TableRow();
TableCell TD = new TableCell();
TD.VerticalAlign = VerticalAlign.Top;
TD.Controls.Add(m_Textbox);
TD.Controls.Add(m_TextboxHiddenID);
TR.Controls.Add(TD);
TD = new TableCell();
TD.VerticalAlign = VerticalAlign.Top;
TD.Width = Unit.Pixel(22);
HtmlButton myButton = new HtmlButton();
myButton.ID = "Button";
myButton.Attributes.Add("onclick", m_Javascript);
myButton.Attributes.Add("class", "SelectBoxButton");
TD.Controls.Add(myButton);
TR.Controls.Add(TD);
myTable.Controls.Add(TR);
Controls.Add(myTable);
}
/// <summary>
/// Override to prevent span
/// </summary>
/// <param name="writer"> The HTML writer to write out to </param>
public override void RenderBeginTag(HtmlTextWriter writer) { }
/// <summary>
/// Override to prevent span
/// </summary>
/// <param name="writer"> The HTML writer to write out to </param>
public override void RenderEndTag(HtmlTextWriter writer) { }
}
}
And the code on the .aspx pages is:
<WorkTech:SelectBox ID="PaymentReciever" Width="200px"
JavaScript="AddPaymentReciever();" runat="server" />
This works fine and supports postback. BUT when i use it in a MultiView with
2 or more Views like this:
<asp:MultiView ID="MultiView1" ActiveViewIndex="0" runat="server">
<asp:View ID="View1" runat="server">
Hello World!<br />
</asp:View>
<asp:View ID="View2" runat="server">
<WorkTech:SelectBox ID="PaymentReciever" Width="200px"
JavaScript="AddPaymentReciever();" runat="server" />
</asp:View>
<asp:View ID="View3" runat="server">
Hello World!<br />
</asp:View>
</asp:MultiView>
The my control looses data if I perfom a postback while View2 is not the
ActiveView.
Example's:
I'm in View2, I fill out the Textboxes, go to View1 and back to View2. That
works
If Im' in View2, fill out the Textboxes, go to View3, then to View1 and then
to View2. Then my data is lost?
I really hope you understand my problem, and that you can help me!
Thanks
Michael
I have a problem with my webcontrol when I use in a MultiView.
I have a fairly simple webcontrol that consists of a Table with one row and
two cells, in the first Cell i have two TextBoxe's (one of which is hidden
from the User) and in the second Cell i have a HtmlButton.
The code is:
namespace WorkTech
{
[ParseChildren(false), ToolboxData("<{0}:SelectBox runat=server />")]
public class SelectBox : System.Web.UI.WebControls.WebControl,
INamingContainer
{
private TextBox m_Textbox;
private TextBox m_TextboxHiddenID;
private string m_Javascript = string.Empty;
public string JavaScript
{
get { return m_Javascript; }
set { m_Javascript = value; }
}
public string Text
{
get { return m_Textbox.Text; }
set { m_Textbox.Text = value; }
}
public Guid HiddenID
{
get { return Functions.ParseGuid(m_TextboxHiddenID.Text); }
set { m_TextboxHiddenID.Text = value.ToString(); }
}
protected override void CreateChildControls()
{
Controls.Clear();
m_Textbox = new TextBox();
m_TextboxHiddenID = new TextBox();
Table myTable = new Table();
m_Textbox.ID = "Textbox";
m_Textbox.CssClass = "TextBox";
if (Width.Type.ToString() == "Pixel" && Width.Value > 0)
{
int TextBoxWidth = Convert.ToInt32((Width.Value - 22));
m_Textbox.Width = Unit.Pixel(TextBoxWidth);
}
m_Textbox.Attributes.Add("readonly", "true");
m_TextboxHiddenID.ID = "HiddenID";
m_TextboxHiddenID.CssClass = "Hidden";
myTable.CellPadding = 0;
myTable.CellSpacing = 0;
TableRow TR = new TableRow();
TableCell TD = new TableCell();
TD.VerticalAlign = VerticalAlign.Top;
TD.Controls.Add(m_Textbox);
TD.Controls.Add(m_TextboxHiddenID);
TR.Controls.Add(TD);
TD = new TableCell();
TD.VerticalAlign = VerticalAlign.Top;
TD.Width = Unit.Pixel(22);
HtmlButton myButton = new HtmlButton();
myButton.ID = "Button";
myButton.Attributes.Add("onclick", m_Javascript);
myButton.Attributes.Add("class", "SelectBoxButton");
TD.Controls.Add(myButton);
TR.Controls.Add(TD);
myTable.Controls.Add(TR);
Controls.Add(myTable);
}
/// <summary>
/// Override to prevent span
/// </summary>
/// <param name="writer"> The HTML writer to write out to </param>
public override void RenderBeginTag(HtmlTextWriter writer) { }
/// <summary>
/// Override to prevent span
/// </summary>
/// <param name="writer"> The HTML writer to write out to </param>
public override void RenderEndTag(HtmlTextWriter writer) { }
}
}
And the code on the .aspx pages is:
<WorkTech:SelectBox ID="PaymentReciever" Width="200px"
JavaScript="AddPaymentReciever();" runat="server" />
This works fine and supports postback. BUT when i use it in a MultiView with
2 or more Views like this:
<asp:MultiView ID="MultiView1" ActiveViewIndex="0" runat="server">
<asp:View ID="View1" runat="server">
Hello World!<br />
</asp:View>
<asp:View ID="View2" runat="server">
<WorkTech:SelectBox ID="PaymentReciever" Width="200px"
JavaScript="AddPaymentReciever();" runat="server" />
</asp:View>
<asp:View ID="View3" runat="server">
Hello World!<br />
</asp:View>
</asp:MultiView>
The my control looses data if I perfom a postback while View2 is not the
ActiveView.
Example's:
I'm in View2, I fill out the Textboxes, go to View1 and back to View2. That
works
If Im' in View2, fill out the Textboxes, go to View3, then to View1 and then
to View2. Then my data is lost?
I really hope you understand my problem, and that you can help me!
Thanks
Michael