LinkButton requires two UI clicks to change cssclass property

H

HillBilly

MasterPages again. Three LinkButtons are being used as styled tabs in the
content page that will load a different ListView when a tab is selected:
TabA, TabB or TabC. The LinkButtons are declared in the apsx and the
LinkButtons are being found in their MasterPage container template(s).
Enabling and disabling the SkinId and CssClass properties for each
LinkButton is being handled in the PreInit of a GlobalBaseClass that
inherits from System.Web.UI.Page.

When a tab is selected a feedbackLabel is updated to indicate which tab was
selected confirming which LinkButton event handler changed the text property
of the feedbackLabel --but-- the style properties are not being updated in
the page until one of any of the three tabs are clicked a second time. The
code which changes the style properties is and must be written into PrInit.

I am using the LinkButton as a command button declared using OnCommand.
However, I must still determine how to resolve the need to click tabs twice
to ensure the displayed tabbed style is consistent with the state of the
rest of the page.

Secondly, what should I consider in the code to evaluate how it has been
written for this type of task? I don't know how to debug this circumstance.

// typical LinkButton declaration
<asp:LinkButton ID="TabA"
SkinID="Tab-On"
EnableViewState="false"
CausesValidation="false"
OnCommand="TabA_OnCommand"
Text="TabA" runat="server"/>

// TabA Event handler
protected void TabA_OnCommand(object sender,
EventArgs e)
{
Session["selectedTab"] = "TabA";

// To be replaced with ListView
Label feedbackLabel =
Master...FindControl("feedbackLabel")
as Label;

feedbackLabel.Text =
string)Session["selectedTab"];
}

//PreInit
string thisPage =
Path.GetFileName(Request.PhysicalPath);

if (IsPostBack)
{
if (!HttpContext.Current.User.Identity.IsAuthenticated
&& thisPage == "BigPainInTheAss.aspx")
{
LinkButton TabA = Master...FindControl("TabA")
as LinkButton;
LinkButton TabB = Master...FindControl("TabB")
as LinkButton;
LinkButton TabC = Master...FindControl("TabC")
as LinkButton;

string selectedTab = (string)Session["selectedTab"];

if (!String.IsNullOrEmpty(selectedTab))
{
switch (selectedTab)
{
case "TabA":
TabA.SkinID = "...";
TabA.CssClass = "...";
...
...
break;
case "TabB":
TabB.SkinID = "...";
TabB.CssClass = "...";
...
...
break;
case "TabC":
TabC.SkinID = "...";
TabC.CssClass = "...";
...
...
break;
default:
...
break;
}//switch
}//if selectedTab
}//if IsAuthenticated
}// if IsPostBack
 
H

HillBilly

Thank you Göran. Two heads are better than one.

Göran Andersson said:
Actually this has nothing to do with master pages, but with the order of
events in a page.


Actually, you don't have to click the tab twice. After clicking a tab you
can do anything that causes a postback to make the tab show up.

The PreInit event occurs before any other of your events, so you are using
the value in the session variable before you are setting it. The result is
that the value that you set in the OnCommand event is used by the PreInit
event of the next postback.


To solve this you need to detect what tab has been clicked in the PreInit
method. The information that you have for this is what's in the
Request.Form collection.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top