C
ChuckSlayer
Can anyone please explain to me why this does not work and how should
I fix it?. I am adding dropdownlists dynamically on the code behind.
These dropdownlists are set not to use autopost back. After the user
is done selecting all desired values for all dropdownlists, they click
on the next button and the event handler is supposed to read their
values. My problem is that it is not working. When the event handler
reads all dropdownlists, their selected index have been reseted to 0
and their view state is lost.
This is my current code which i am attempting to do with a ASP:Table
(I tried with panels and placeholders and got the same result)
-------------Design View ------------------------------
<fieldset id="import">
<legend>Pre-Import</legend>
The following headers were found on the file you provided.<br />
Please map your headers with the headers used on this version of
TreeFrog<br />
<br />
<asp:Table id="tbUser" GridLines="Both" HorizontalAlign="Center"
Font-Names="Verdana" CellPadding="0" CellSpacing="0" Runat="server"/>
<br />
<cc:ServerImageButton ID="ibProceedEnabled" runat="server"
Text="Proceed" ButtonType="ImportContacts" IncludeDiv="false"
OnClick="cmdImportContacts"/>
<cc:ServerImageButton ID="ibCancel" runat="server" Text="Cancel"
ButtonType="cancel" IncludeDiv="false" OnClick="cmdCancelExit"/>
</fieldset>
----------------------End Design View
--------------------------------------------
------------------- Code Behind (Page Load)
------------------------------
protected void Page_Init(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
cmdCancelExit(sender, e);
return;
}
userHeaders = GetHeaders(MyFileContent);
validHeaders = GetValidHeader();
for (int i = 0; i<userHeaders.Count; i++)
{
trUser = new TableRow();
tcUser = new TableCell();
tcUser.Text = userHeaders;
trUser.Controls.Add(tcUser);
DropDownList ddlHtml = new DropDownList();
ddlHtml.ID = "ddlValidHeaders_" + i;
ddlHtml.DataSource = validHeaders;
ddlHtml.DataBind();
ListItem li = new ListItem("None", "");
ddlHtml.Items.Insert(0,li);
tcUser = new TableCell();
tcUser.Controls.Add(ddlHtml);
trUser.Controls.Add(tcUser);
tbUser.Controls.Add(trUser);
ddlHtml.Attributes.Add("onchange",
"toggleDropDowns(this,'" + ddlHtml.ClientID + "'," + userHeaders.Count
+ "," + validHeaders.Count + ");");
}
}
catch (Exception exc)
{
DnnMsgEventArgs msgArgs = new
DnnMsgEventArgs(exc.Message,
DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError,
this);
OnDnnMsgEvent(msgArgs);
}
}
---------------- End Code Behind (Page
Load)-----------------------------
I fix it?. I am adding dropdownlists dynamically on the code behind.
These dropdownlists are set not to use autopost back. After the user
is done selecting all desired values for all dropdownlists, they click
on the next button and the event handler is supposed to read their
values. My problem is that it is not working. When the event handler
reads all dropdownlists, their selected index have been reseted to 0
and their view state is lost.
This is my current code which i am attempting to do with a ASP:Table
(I tried with panels and placeholders and got the same result)
-------------Design View ------------------------------
<fieldset id="import">
<legend>Pre-Import</legend>
The following headers were found on the file you provided.<br />
Please map your headers with the headers used on this version of
TreeFrog<br />
<br />
<asp:Table id="tbUser" GridLines="Both" HorizontalAlign="Center"
Font-Names="Verdana" CellPadding="0" CellSpacing="0" Runat="server"/>
<br />
<cc:ServerImageButton ID="ibProceedEnabled" runat="server"
Text="Proceed" ButtonType="ImportContacts" IncludeDiv="false"
OnClick="cmdImportContacts"/>
<cc:ServerImageButton ID="ibCancel" runat="server" Text="Cancel"
ButtonType="cancel" IncludeDiv="false" OnClick="cmdCancelExit"/>
</fieldset>
----------------------End Design View
--------------------------------------------
------------------- Code Behind (Page Load)
------------------------------
protected void Page_Init(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
cmdCancelExit(sender, e);
return;
}
userHeaders = GetHeaders(MyFileContent);
validHeaders = GetValidHeader();
for (int i = 0; i<userHeaders.Count; i++)
{
trUser = new TableRow();
tcUser = new TableCell();
tcUser.Text = userHeaders;
trUser.Controls.Add(tcUser);
DropDownList ddlHtml = new DropDownList();
ddlHtml.ID = "ddlValidHeaders_" + i;
ddlHtml.DataSource = validHeaders;
ddlHtml.DataBind();
ListItem li = new ListItem("None", "");
ddlHtml.Items.Insert(0,li);
tcUser = new TableCell();
tcUser.Controls.Add(ddlHtml);
trUser.Controls.Add(tcUser);
tbUser.Controls.Add(trUser);
ddlHtml.Attributes.Add("onchange",
"toggleDropDowns(this,'" + ddlHtml.ClientID + "'," + userHeaders.Count
+ "," + validHeaders.Count + ");");
}
}
catch (Exception exc)
{
DnnMsgEventArgs msgArgs = new
DnnMsgEventArgs(exc.Message,
DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError,
this);
OnDnnMsgEvent(msgArgs);
}
}
---------------- End Code Behind (Page
Load)-----------------------------