N
nLL
Hi, i'm new to .net and having problem with a dropdown list.
Basically i can not get selected index of extractedCss dropdown list on
SaveTagButton_Click event. selected index always -1
i have read couple of articles that says do not re-bind on post bask or
do not put databind in page load event but none of my data binding is in
page load event anyway.
here is the code
-------------------------
using System;
using System.Configuration;
using System.Web.UI.WebControls;
// tags etc
//id,pageId,tagType,tagRelatedId,tagText,
//tagStyleClass,tagFrontColor,tagFontDecoration,tagFontWeight,tagFontSize,tagBgColor,
//tagBorderSize,tagBorderColor,tagHorizantalAlign,positionInPage
public partial class manage_manageSiteEditPageAddNewItem :
System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Functions f = new Functions();
if (f.LoginCheck() == true)
{
string connString =
ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
int subdomainid =
Functions.ReturnNumeric(Request["subdomainid"]);
string subdomain = f.GetSubdomainNameById(subdomainid);
int pageid = Functions.ReturnNumeric(Request["pageid"]);
// get prviosu position. if 0 that means there are no
previous elements
int prevPositiontagid =
Functions.ReturnNumeric(Request["prevPositiontagid"]);
}
else
{
//login wrong
loggedinDiv.Visible = false;
notLoggedInDiv.Visible = true;
}
}
public void ExtractCSS(string subdomain)
{
// extract css from stlysheet
myPageBuilder builder = new myPageBuilder();
Panel_tagStyleClass.Visible = true;
extractedCss.DataSource = builder.CssExtract(subdomain);
extractedCss.DataTextField = "Cssclass";
extractedCss.DataValueField = "Cssclass";
extractedCss.DataBind();
extractedCss.Items.Insert(0, new ListItem("Not configured", ""));
}
public void BuildFontColourList()
{
myPageBuilder builder = new myPageBuilder();
FontColourList.DataSource = builder.colourList();
FontColourList.DataValueField = "ColorHex";
FontColourList.DataTextField = "ColorName";
FontColourList.DataBind();
FontColourList.Items.Insert(0, new ListItem("Not
configured", ""));
foreach (ListItem li in FontColourList.Items)
{
li.Attributes["style"] = "background-color: " +
li.Value;
}
}
public void BuildTagBgColorList()
{
myPageBuilder builder = new myPageBuilder();
tagBgColorList.DataSource = builder.colourList();
tagBgColorList.DataValueField = "ColorHex";
tagBgColorList.DataTextField = "ColorName";
tagBgColorList.DataBind();
tagBgColorList.Items.Insert(0, new ListItem("Not configured", ""));
foreach (ListItem lili in tagBgColorList.Items)
{
lili.Attributes["style"] = "background-color: " + lili.Value;
}
}
public void BuildTagBorderColourList()
{
myPageBuilder builder = new myPageBuilder();
tagBorderColourList.DataSource = builder.colourList();
tagBorderColourList.DataValueField = "ColorHex";
tagBorderColourList.DataTextField = "ColorName";
tagBorderColourList.DataBind();
tagBorderColourList.Items.Insert(0, new ListItem("Not
configured", ""));
foreach (ListItem lilil in tagBorderColourList.Items)
{
lilil.Attributes["style"] = "background-color: " + lilil.Value;
}
}
protected void addTagButton_Click (object sender, EventArgs e)
{
Functions f = new Functions();
myPageBuilder builder = new myPageBuilder();
int subdomainid = Functions.ReturnNumeric(Request["subdomainid"]);
string subdomain = f.GetSubdomainNameById(subdomainid);
string selectedTag = tagList.SelectedValue.ToString();
Panel panelToShow = (Panel)loggedinDiv.FindControl("Panel_" +
selectedTag);// ("Panel_LineBreak");
// show selected panel
panelToShow.Visible = true;
// show style options taxt
styleOptionsLabel.Visible = true;
manualStyleOptionsLabel.Visible = true;
// extract style shee
ExtractCSS(subdomain);
// show save buttons
SaveTagButtonPanel1.Visible = true;
//tag spesific properties
switch (selectedTag)
{
case "LineBreak":
tagType.Value = "LineBreak";
break;
case "Text":
tagType.Value = "Text";
Panel_tagFontColor.Visible = true;
Panel_tagFontDecoration.Visible = true;
Panel_tagFontWeight.Visible = true;
Panel_tagFontSize.Visible = true;
Panel_tagBgColor.Visible = true;
Panel_tagBorderSize.Visible = true;
Panel_tagBorderColor.Visible = true;
SaveTagButtonPanel2.Visible = true;
BuildFontColourList();
BuildTagBgColorList();
BuildTagBorderColourList();
break;
case "TextLink":
tagType.Value = "TextLink";
Panel_tagFontColor.Visible = true;
Panel_tagFontDecoration.Visible = true;
Panel_tagFontWeight.Visible = true;
Panel_tagFontSize.Visible = true;
SaveTagButtonPanel2.Visible = true;
BuildFontColourList();
break;
case "Image":
tagType.Value = "Image";
Panel_tagBorderSize.Visible = true;
Panel_tagBorderColor.Visible = true;
SaveTagButtonPanel2.Visible = true;
BuildTagBorderColourList();
break;
case "ImageLink":
tagType.Value = "ImageLink";
Panel_tagBorderSize.Visible = true;
Panel_tagBorderColor.Visible = true;
SaveTagButtonPanel2.Visible = true;
BuildTagBorderColourList();
break;
case "HtmlCode":
tagType.Value = "HtmlCode";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "CodeSnippet":
tagType.Value = "CodeSnippet";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "LinkRotator":
tagType.Value = "LinkRotator";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "AdmobAdvert":
tagType.Value = "AdmobAdvert";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "AdultmodaAdvert":
tagType.Value = "HtmlCode";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "AdmodaAdvert":
tagType.Value = "AdmodaAdvert";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "BuzzcityAdvert":
tagType.Value = "BuzzcityAdvert";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "DecktradeAdvert":
tagType.Value = "DecktradeAdvert";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "GoogleAdvert":
tagType.Value = "GoogleAdvert";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "MojivaAdvert":
tagType.Value = "MojivaAdvert";
Panel_tagStyleClass.Visible =false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
//default: other++; break;
}
}
protected void SaveTagButton_Click (object sender, EventArgs e)
{
Functions f = new Functions();
SaveButtonResultPanel.Visible = true;
string TagTypeToSave =
Functions.LimitString(tagType.Value.ToString(),20);
TagTypeToSave = Server.HtmlEncode(TagTypeToSave);
TagTypeToSave = f.SqlProtect(TagTypeToSave);
//string CssClassToSave =
Functions.LimitString(extractedCss.SelectedValue.ToString(),20);
Response.Write(extractedCss.SelectedIndex.ToString());
//string CssClassToSave;
//CssClassToSave = Server.HtmlEncode(CssClassToSave);
//CssClassToSave = f.SqlProtect(CssClassToSave);
string FontSizeToSave =
Functions.LimitString(fontSizeList.SelectedValue.ToString(),20);
FontSizeToSave = Server.HtmlEncode(FontSizeToSave);
FontSizeToSave = f.SqlProtect(FontSizeToSave);
string FontColourToSave =
Functions.LimitString(FontColourList.SelectedValue.ToString(),20);
FontColourToSave = Server.HtmlEncode(FontColourToSave);
FontColourToSave = f.SqlProtect(FontColourToSave);
string FontDecorationToSave =
Functions.LimitString(fontDecorationList.SelectedValue.ToString(),20);
FontDecorationToSave = Server.HtmlEncode(FontDecorationToSave);
FontDecorationToSave = f.SqlProtect(FontDecorationToSave);
string FontWeightToSave =
Functions.LimitString(fontWeightList.SelectedValue.ToString(),20);
FontWeightToSave = Server.HtmlEncode(FontWeightToSave);
FontWeightToSave = f.SqlProtect(FontWeightToSave);
string TagBgColorToSave =
Functions.LimitString(tagBgColorList.SelectedValue.ToString(),20);
TagBgColorToSave = Server.HtmlEncode(TagBgColorToSave);
TagBgColorToSave = f.SqlProtect(TagBgColorToSave);
int TagtagBorderSizeToSave =
Functions.ReturnNumeric(tagBorderSizeList.SelectedValue.ToString());
string TagBorderColourToSave =
Functions.LimitString(tagBorderColourList.SelectedValue.ToString(), 20);
TagBorderColourToSave = Server.HtmlEncode(TagBorderColourToSave);
TagBorderColourToSave = f.SqlProtect(TagBorderColourToSave);
switch (TagTypeToSave)
{
case "Text":
string TextToSave=
Functions.LimitString(TextText.Text.ToString(),500);
TextToSave = Server.HtmlEncode(TextToSave);
TextToSave = f.SqlProtect(TextToSave);
SaveButtonResultLabel.Text = TextToSave;// TextToSave;
break;
}
}
}
Basically i can not get selected index of extractedCss dropdown list on
SaveTagButton_Click event. selected index always -1
i have read couple of articles that says do not re-bind on post bask or
do not put databind in page load event but none of my data binding is in
page load event anyway.
here is the code
-------------------------
using System;
using System.Configuration;
using System.Web.UI.WebControls;
// tags etc
//id,pageId,tagType,tagRelatedId,tagText,
//tagStyleClass,tagFrontColor,tagFontDecoration,tagFontWeight,tagFontSize,tagBgColor,
//tagBorderSize,tagBorderColor,tagHorizantalAlign,positionInPage
public partial class manage_manageSiteEditPageAddNewItem :
System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Functions f = new Functions();
if (f.LoginCheck() == true)
{
string connString =
ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
int subdomainid =
Functions.ReturnNumeric(Request["subdomainid"]);
string subdomain = f.GetSubdomainNameById(subdomainid);
int pageid = Functions.ReturnNumeric(Request["pageid"]);
// get prviosu position. if 0 that means there are no
previous elements
int prevPositiontagid =
Functions.ReturnNumeric(Request["prevPositiontagid"]);
}
else
{
//login wrong
loggedinDiv.Visible = false;
notLoggedInDiv.Visible = true;
}
}
public void ExtractCSS(string subdomain)
{
// extract css from stlysheet
myPageBuilder builder = new myPageBuilder();
Panel_tagStyleClass.Visible = true;
extractedCss.DataSource = builder.CssExtract(subdomain);
extractedCss.DataTextField = "Cssclass";
extractedCss.DataValueField = "Cssclass";
extractedCss.DataBind();
extractedCss.Items.Insert(0, new ListItem("Not configured", ""));
}
public void BuildFontColourList()
{
myPageBuilder builder = new myPageBuilder();
FontColourList.DataSource = builder.colourList();
FontColourList.DataValueField = "ColorHex";
FontColourList.DataTextField = "ColorName";
FontColourList.DataBind();
FontColourList.Items.Insert(0, new ListItem("Not
configured", ""));
foreach (ListItem li in FontColourList.Items)
{
li.Attributes["style"] = "background-color: " +
li.Value;
}
}
public void BuildTagBgColorList()
{
myPageBuilder builder = new myPageBuilder();
tagBgColorList.DataSource = builder.colourList();
tagBgColorList.DataValueField = "ColorHex";
tagBgColorList.DataTextField = "ColorName";
tagBgColorList.DataBind();
tagBgColorList.Items.Insert(0, new ListItem("Not configured", ""));
foreach (ListItem lili in tagBgColorList.Items)
{
lili.Attributes["style"] = "background-color: " + lili.Value;
}
}
public void BuildTagBorderColourList()
{
myPageBuilder builder = new myPageBuilder();
tagBorderColourList.DataSource = builder.colourList();
tagBorderColourList.DataValueField = "ColorHex";
tagBorderColourList.DataTextField = "ColorName";
tagBorderColourList.DataBind();
tagBorderColourList.Items.Insert(0, new ListItem("Not
configured", ""));
foreach (ListItem lilil in tagBorderColourList.Items)
{
lilil.Attributes["style"] = "background-color: " + lilil.Value;
}
}
protected void addTagButton_Click (object sender, EventArgs e)
{
Functions f = new Functions();
myPageBuilder builder = new myPageBuilder();
int subdomainid = Functions.ReturnNumeric(Request["subdomainid"]);
string subdomain = f.GetSubdomainNameById(subdomainid);
string selectedTag = tagList.SelectedValue.ToString();
Panel panelToShow = (Panel)loggedinDiv.FindControl("Panel_" +
selectedTag);// ("Panel_LineBreak");
// show selected panel
panelToShow.Visible = true;
// show style options taxt
styleOptionsLabel.Visible = true;
manualStyleOptionsLabel.Visible = true;
// extract style shee
ExtractCSS(subdomain);
// show save buttons
SaveTagButtonPanel1.Visible = true;
//tag spesific properties
switch (selectedTag)
{
case "LineBreak":
tagType.Value = "LineBreak";
break;
case "Text":
tagType.Value = "Text";
Panel_tagFontColor.Visible = true;
Panel_tagFontDecoration.Visible = true;
Panel_tagFontWeight.Visible = true;
Panel_tagFontSize.Visible = true;
Panel_tagBgColor.Visible = true;
Panel_tagBorderSize.Visible = true;
Panel_tagBorderColor.Visible = true;
SaveTagButtonPanel2.Visible = true;
BuildFontColourList();
BuildTagBgColorList();
BuildTagBorderColourList();
break;
case "TextLink":
tagType.Value = "TextLink";
Panel_tagFontColor.Visible = true;
Panel_tagFontDecoration.Visible = true;
Panel_tagFontWeight.Visible = true;
Panel_tagFontSize.Visible = true;
SaveTagButtonPanel2.Visible = true;
BuildFontColourList();
break;
case "Image":
tagType.Value = "Image";
Panel_tagBorderSize.Visible = true;
Panel_tagBorderColor.Visible = true;
SaveTagButtonPanel2.Visible = true;
BuildTagBorderColourList();
break;
case "ImageLink":
tagType.Value = "ImageLink";
Panel_tagBorderSize.Visible = true;
Panel_tagBorderColor.Visible = true;
SaveTagButtonPanel2.Visible = true;
BuildTagBorderColourList();
break;
case "HtmlCode":
tagType.Value = "HtmlCode";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "CodeSnippet":
tagType.Value = "CodeSnippet";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "LinkRotator":
tagType.Value = "LinkRotator";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "AdmobAdvert":
tagType.Value = "AdmobAdvert";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "AdultmodaAdvert":
tagType.Value = "HtmlCode";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "AdmodaAdvert":
tagType.Value = "AdmodaAdvert";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "BuzzcityAdvert":
tagType.Value = "BuzzcityAdvert";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "DecktradeAdvert":
tagType.Value = "DecktradeAdvert";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "GoogleAdvert":
tagType.Value = "GoogleAdvert";
Panel_tagStyleClass.Visible = false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
case "MojivaAdvert":
tagType.Value = "MojivaAdvert";
Panel_tagStyleClass.Visible =false;
styleOptionsLabel.Visible = false;
manualStyleOptionsLabel.Visible = false;
break;
//default: other++; break;
}
}
protected void SaveTagButton_Click (object sender, EventArgs e)
{
Functions f = new Functions();
SaveButtonResultPanel.Visible = true;
string TagTypeToSave =
Functions.LimitString(tagType.Value.ToString(),20);
TagTypeToSave = Server.HtmlEncode(TagTypeToSave);
TagTypeToSave = f.SqlProtect(TagTypeToSave);
//string CssClassToSave =
Functions.LimitString(extractedCss.SelectedValue.ToString(),20);
Response.Write(extractedCss.SelectedIndex.ToString());
//string CssClassToSave;
//CssClassToSave = Server.HtmlEncode(CssClassToSave);
//CssClassToSave = f.SqlProtect(CssClassToSave);
string FontSizeToSave =
Functions.LimitString(fontSizeList.SelectedValue.ToString(),20);
FontSizeToSave = Server.HtmlEncode(FontSizeToSave);
FontSizeToSave = f.SqlProtect(FontSizeToSave);
string FontColourToSave =
Functions.LimitString(FontColourList.SelectedValue.ToString(),20);
FontColourToSave = Server.HtmlEncode(FontColourToSave);
FontColourToSave = f.SqlProtect(FontColourToSave);
string FontDecorationToSave =
Functions.LimitString(fontDecorationList.SelectedValue.ToString(),20);
FontDecorationToSave = Server.HtmlEncode(FontDecorationToSave);
FontDecorationToSave = f.SqlProtect(FontDecorationToSave);
string FontWeightToSave =
Functions.LimitString(fontWeightList.SelectedValue.ToString(),20);
FontWeightToSave = Server.HtmlEncode(FontWeightToSave);
FontWeightToSave = f.SqlProtect(FontWeightToSave);
string TagBgColorToSave =
Functions.LimitString(tagBgColorList.SelectedValue.ToString(),20);
TagBgColorToSave = Server.HtmlEncode(TagBgColorToSave);
TagBgColorToSave = f.SqlProtect(TagBgColorToSave);
int TagtagBorderSizeToSave =
Functions.ReturnNumeric(tagBorderSizeList.SelectedValue.ToString());
string TagBorderColourToSave =
Functions.LimitString(tagBorderColourList.SelectedValue.ToString(), 20);
TagBorderColourToSave = Server.HtmlEncode(TagBorderColourToSave);
TagBorderColourToSave = f.SqlProtect(TagBorderColourToSave);
switch (TagTypeToSave)
{
case "Text":
string TextToSave=
Functions.LimitString(TextText.Text.ToString(),500);
TextToSave = Server.HtmlEncode(TextToSave);
TextToSave = f.SqlProtect(TextToSave);
SaveButtonResultLabel.Text = TextToSave;// TextToSave;
break;
}
}
}