Hiding first TabPanel of TabContainer hides the TabContainer - asp.net

I have an ajax tab container with 3 tabs.the problem is that when I make the first tab invisible,it makes the entire tab container invisible.
i have something like
<tk:TabContainer ID="TabContainer1" runat="server" >
<tk:TabPanel ID="Tabpanell" runat="server" >
</tk:TabPanel>
<tk:TabPanel ID="Tabpanel2" runat="server" >
</tk:TabPanel>
<tk:TabPanel ID="Tabpanel3" runat="server" >
</tk:TabPanel>
</tk:TabContainer>
and in code behind,on page load i need to show only some tabpanels based on condition that is..
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!CheckViewPermissionTab1())
{
Tabpanel1.visible=false;
}
}
}
but when i try to set the first tabpanel's visibilit to false ,the entire tab container gets hidden.There is no problem whwn the second or third panel's visibility is set to false.

The problem is tabcontainer need atleast a tab should be active otherwise it will go invisible so if you set a tab to visible=false, then you have to set any other tab to be active.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!CheckViewPermissionTab1())
{
Tabpanel1.visible=false;
TabContainer1.ActiveTab = Tabpanel2;
}
}
}
Try the above code.

Related

DropDownList AutoPostBack not hitting break point

The auto post back for my drop down list is not hitting the break point in the code behind. It appears that changing the value of the drop down list is not causing the post back at all.
<asp:DropDownList ID="RidingType" runat="server" CssClass="option" DataValueField="VarId" DataTextField="Name" AutoPostBack="true" OnSelectedIndexChanged="RidingType_SelectedIndexChanged"></asp:DropDownList>
I have tried both OnSelectedIndexChanged and OnTextChanged. I am doing something similar on a different page, where it does work as expected.
<asp:DropDownList CssClass="listBoxes" runat="server" ID="lstBrands" DataValueField="brand" DataTextField="brand" AutoPostBack="true" OnTextChanged="lstBrands_SelectedIndexChanged" Width="100%"></asp:DropDownList>
I've done everything I can to match up the surrounding environments. Any ideas as to why the first appears not to post back and the second works correctly?
Edit:
Here is an excerpt from the code behind the binding function
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
/* code to set up other drop down lists */
BindRidingType();
/* more of the same */
}
}
private void BindRidingType()
{
prams[3].Value = "Riding Type";
RidingType.DataSource = ReturnSelection(prams); //return DataTable from Database
RidingType.SelectedValue = DefaultValue("Riding Type"); //Finds default value for list
RidingType.DataBind();
}
Per suggestion I tried not setting a default value, but I saw no change.
Edit:
The event handler as requested
protected void RidingType_SelectedIndexChanged(object sender, EventArgs e)
{
throw new NotImplementedException();
}

Store the Contents of a Panel Control into a Cookie

I created a page, which allows users the option to show or hide it's content sections via a show/hide button. After clicking the show/hide button, the nested panels/content becomes visible or invisible based on the button selected, then the user may save the page by clicking a save button. Problem - (no errors) but, the page is not saving the users changes into the cookie. The page contains 2 panel controls that are nested in one main Panel control.
//Front End code - The save button
<asp:Button ID="savButton" runat="server" Text="Save" onclick="savButton_Click" />
//psuedo code - The Panels
<asp:Panel ID="pnlSaveContent" runat="server"> //main Panel control
<asp:Panel ID="pnlWeatherAppCtrl" runat="server"> // panel content 1
<div>Weather App Content</div>
</Panel>
<asp:Panel ID="StockAppCtrl" runat="server"> // panel content 2
<div>Stock App Content</div>
</Panel>
</Panel>
//Back-end code:
protected void Page_Load(object sender, EventArgs e)
{
//get the cookie
if ((Request.Cookies["preferences"] != null))
{
pnlSaveContent.ID = Request.Cookies["preferences"]["savePg"];
}
}
//set cookie
protected void savButton_Click(object sender, EventArgs e)
{
Response.Cookies["preferences"]["savePg"] = pnlSaveContent.ID;
Response.Cookies["preferences"].Expires = DateTime.MaxValue;
}
//end code
...the issue: The page is not saving the changes of the main panel control. Could someone please provide some guidance as to what I’m doing wrong?
Don't forget to save the cookie with Response.Cookies.Add:
protected void savButton_Click(object sender, EventArgs e)
{
HttpCookie c = Request.Cookies["preferences"] != null ?
Request.Cookies["preferences"] :
new HttpCookie("preferences");
c.Values["savePg"] = pnlSaveContent.ID;
c.Expires = DateTime.MaxValue;
Response.Cookies.Add(c);
}
As for your comment... I'm not quite sure what you are trying to do, but maybe it is this. This will set the visibility of the panel depending on the value of the cookie (visibility is false if the ID matches the value of cookie).
protected void Page_Load(object sender, EventArgs e)
{
//get the cookie
if ((Request.Cookies["preferences"] != null))
{
pnlSaveContent.Visible = !(pnlSaveContent.ID == Request.Cookies["preferences"]["savePg"]);
}
}

(ModalPopupExtender) two components with the same id can't be added to the application

I have a user control which I add on a page whenever user click on button. Following is the code to add control.
protected void Page_Init(object sender, EventArgs e)
{
if (Session["ControlCount"] != null)
{
for (int i = 1; i <= (int)Session["ControlCount"]; i++)
{
Control myUserControl = LoadControl("~/Controls/MessageControl.ascx");
divMessageControl.Controls.Add(myUserControl);
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnExpand_Click(object sender, EventArgs e)
{
int count = 0;
if (Session["ControlCount"] != null)
{
count = Convert.ToInt32(Session["ControlCount"]);
}
Control myUserControl = (Control)Page.LoadControl("~/Controls/MessageControl.ascx");
divMessageControl.Controls.Add(myUserControl);
Session["ControlCount"] = count + 1;
}
This control has ModalPopupExtender popup. When I add 2nd control on page it throws an error internally which i can see in firebug. How to make this popup id unique?
<asp:ModalPopupExtender ID="mpeReply" BehaviorID="mpeReply" runat="server" TargetControlID="btnReply"
PopupControlID="pnlReply" BackgroundCssClass="ModalPopupBG1">
</asp:ModalPopupExtender>
Sys.InvalidOperationException: Sys.InvalidOperationException: Two
components with the same id 'mpeReply' can't be added to the
application.
I have found the solution to this problem, as much as a lot of people have said, the simple solution is that your HTML is not properly formed - there is either an extra or missing closing tag to an element. Make sure that all your tags are properly closed and the problem should go away - struggled all day with this one!
I used this code to fix my problem, notice the ScriptMode is set to "Release"
<AjaxControlToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" ScriptMode="Release">
</AjaxControlToolkit:ToolkitScriptManager>
I see a similar answer from this link:
http://www.advancesharp.com/questions/17658/sys-invalidoperationexception-two-components-with-the-same-id-xxx-can-t-be-added-to-the-application
Remove BehaviorID property from extender
Similar issue here. The solution for me was to change the Script Manager from a shortcut close tag to the full close tag , after adding the ScriptMode="Release" attribute:
Change:
<asp:ScriptManager ID="ScriptManager1" ScriptMode="Release" runat="server" />
to:
<asp:ScriptManager ID="ScriptManager1" ScriptMode="Release" runat="server></asp:ScriptManager>

Why ispostback not working with dropdown box

I want to keep selected item after page reload:
Excerpt from .aspx:
<asp:DropDownList ID="MyDropDown" runat="server" AutoPostBack="true"
onselectedindexchanged="MyDropDown_SelectedIndexChanged">
</asp:DropDownList>
Exerpt from .cs in page_load
if (!IsPostBack)
{
PopulateDropDownList();
}
with
private void PopulateDropDownList()
{
MyDropDown.Items.Add("1");
MyDropDown.Items.Add("2");
}
protected void MyDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Redirect(Request.RawUrl);
}
Response.Redirect refresh the page and you will loose view state that will have selected index. You can put the selected index in session before redirecting.
protected void MyDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
Session["MyDropDownSelectedIndex"] = MyDropDown.SelectedIndex.ToString();
Response.Redirect(Request.RawUrl);
}
You need to populate the drop down list in the Page init event. If you do that during Page load event the view state cannot be restored correctly (because the drop down list is not populated before Page load event) so the on selected index changed event cannot be fired.
EDIT: you may want to cache the data which populate the drop down list to save some around trip to the database. I think you do not need to redirect in the on selected index changed event too.

GridView paging allowed but disabled, possible?

For a GridView, is there any way I can have AllowPaging="true" but have the pagination links disabled (still visible but not clickable)?
(It's for when the user decides to edit the GridView. In edit mode, Labels inside cells become TextBoxes.)
I've tried Enabled="false" but this disables everything, including the TextBoxes.
I suppose I could handle paging on the server side but I'd rather just disable the pagination links if it's possible.
Any ideas appreciated!
I would hide Pager on RowEditing and show it again on Cancel or Update:
void CustomerGridView_RowEditing(Object sender, GridViewEditEventArgs e)
{
// Hide the pager row.
CustomerGridView.PagerSettings.Visible = false;
}
void CustomerGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Cancel" || e.CommandName == "Update")
{
// Show the pager row.
CustomerGridView.PagerSettings.Visible = true;
}
}

Resources