TabContainer goes Invisible when I make child tab visible = false - c#

I've been struggling with this for a day. Not finding any others with my exact situation, so I figured I'd post and answer with what worked for me.
Environment: Asp.net 4.0 - AjaxControlToolkit v.7.1213.0
Problem: I have a TabContainer with 3 tabs, and based on a database value, I will make the 2nd tab invisible or not. My problem is that when I make that second tab invisible it makes the entire tabContainer invisible. When I inspect source, I can see the control is rendered on the page (tested in Firefox And Chrome), but there's now a style tag (visibility:hidden) that is coming from somewhere NOT in my code (master page, child page, style.css, c# codebehind files, etc), as far as I can tell. I have yet to find an explanation for this errant style tag. I'm not an ASP.net master, so it could be some idiosyncracy with my code, but it's also possible that this is a bug with AjaxControltoolkit.
I'll answer this with the workaround that is currently working for me.

Workaround:
Since I only need to remove / hide this from my users, I am able to use the Tabcontainer.Remove method. When using this method, my tabContainer no longer disappears after postback when it contains an invisible tab.
I replaced:
if(x.value == true)
tabpanel1.Visible == false;
with:
if(x.value == true)
tabContainer1.Tabs.Remove(tabpanel1);

Related

FieldValidators and Visual Web Part (Sharepoint 2010)

I have a visual web part (a simple form) with RequiredFieldValidators. But a problem has occured since the field validators block editing of the page. When i press Edit Page in Sharepoint it starts to load then the validators fire and the javascript is stopped.
I found a solution but i cant get it to work.
Like this
public override void CreateChildControls()
{
if(SPContext.Current.FormContext.FormMode == SPControlMode.Edit)
((UserControl)_ctl).EnableValidators(false);
((UserControl)_ctl).EnableValidators(true);
}
//But the _ctl does not exit i only have
Control control = Page.LoadControl(_ascxPath);
A litte advice would help this sharepoint noob a great deal.
The form is just Labels, Inputs, a button, updatepanel and requiredFieldValidators
Can you not just set the ValidationGroup for the validators and button? Like this: http://msdn.microsoft.com/en-us/library/ms227424.aspx
The validators should only fire when the button is pressed.
There is something wrong with your configuration - I tested this configuration and the required field validators definitely don't block editing on the page. Do you want to post your page and your code behind? Might help to troubleshoot the problem.

Click Gmail Refresh button

I am writing a simple personal app that has a browser control and I want it to automatically "Refresh" gmail to check it more often than it does by default. There are monkey scripts that do this but I'm trying to add my personal style to it.
Anyhow, I've looked around and found everything but what I can do in csharp using the browser control.
I found this:
// Link the ID from the web form to the Button var
theButton = webBrowser_Gmail.Document.GetElementById("Refresh");
// Now do the actual click.
theButton.InvokeMember("click");
But it comes back with null in 'theButton' so it doesn't invoke anything.
Anyone have any suggestions?
It's been awhile since I've used JavaScript, but given the other answers and comments that there is no real ID associated with the element, could you do something like the following:
Search all Div's with an attribute of Role == 'Button' and an InnerHtml == 'Refresh'.
Once the correct InnerHtml is found, get the Element.
Invoke the click on the found Element.
Again, this may be blowing smoke, but thought I'd throw it out there.
edit: Just realized you are doing this with C# and a browser control; however, the concept would still be the same.
The best suggestion I could give you at this point involves an existing API that is used for .NET web browser based automation:
http://watin.org/
Since the div tag with the desired button really only seems to identify itself with the class name, you could use the Find.BySelector(“”) code included with the most recent version of watin.

Issue With Telerik Input Controls

I have a shared user control. This UC is in one page and everything works fine. In the second page, the RadTextBox client-API get_value() method reports "", when it has a legitimate value. There is very little javascript on that page, and it's not targeting textboxes; it's in a page with 6 tabs. The controls work fine; I have RadCombo's and the drop downs work as you would expect. But no text, no selected value, nothing is being reported (I have a script to check if the page is an empty form). How do I even debug this to figure out what is going on, and why the value isn't being reported?
Thanks.
My advice is to start with debugging your js code and see whether the telerik inputs' client objects are valid in your context. If so, rhe methods from their client API should return the values set from the end user.
It was a duplicate method name in a user control,copied twice, so that's why it was bombing. Thanks.

javascript viewstate problem

I have a situation that I am stuck with, and hoping someone can help. I am building a .NET/C# web application in which I have a tabbed panel layout, and when the user clicks on each of the tabs the display panel is updated using javascript to hide and show some divs. None of these clicks cause postback, it is all client-side, so I can't use viewstate or session.
What I want to do is somehow remember which panel was last visible when the page is refreshed, yet without posting back to the server I am unsure how to do this. I have tried a hidden field but obviously its value is reset every time because the form is never submitted. I do know that I can achieve this using cookies but its a little annoying to implement for such a (seemingly) trivial operation ... but maybe this is the only way?
Does anyone have any more elegant solution to this problem?
Using a function like this to show and hide tabs):
function makeCurrent(tab) {
if (tab.title == 'Manage orders') {
document.getElementById('panelOrders').style.display = "block";
// Hide others
document.getElementById('panelAccounts').style.display = "none";
document.getElementById('panelProducts').style.display = "none";
document.getElementById('panelSettings').style.display = "none";
// Remember last viewed panel
document.getElementById('hdnCurrentlyViewing').value = "orders";
}
The panels are just divs with style.display controlling their visibility. Not sure if its useful to post HTML code because its fairly self explanatory ...?
You can make this happen without a postback is to make an AJAX call from Javascript where you tell your server what the current panel is as you switch it.
I prefer using a framework like JQuery or Prototype to help make these AJAX calls myself.
I think Hidden field will be the best option. have you tried ASP:HiddenField? It can be accessed across postbacks.
But if you still have some reservations with postbacks and hiddenfield you can also use cookies from JS http://techpatterns.com/downloads/javascript_cookies.php this is helper lib for cookies manipulation within JS.
Regards.

XML Tags in asp:TextBox prevents other controls working?

I have a series of controls on an ASP page. Some are inside an UpdatePanel and some are not.
If I put an XML tag in one of the text boxes (eg, "<foo>") then all the controls within the UpdatePanel don't work. As soon as the tags are removed, everything is fine.
My 'submit' button is in the UpdatePanel and the breakpoint on btnSubmit_Click is only hit when there aren't tags in the text boxes.
I'm a long-time C# dev but quite new to ASP.NET so might be missing something obvious... this just isn't the behaviour I expect.
If you were to take the UpdatePanel off the page, you'd find that the postback was causing an error because .NET thinks that "<foo>" is a potentially dangerous bit of data to accept at the server. See this question on StackOverflow. You don't see the error because the error page HTML is being returned to the UpdatePanel's ajax call rather than direct to you browser, and the UpdatePanel doesn't know what to do with it.
You can turn off the checking by adding
ValidateRequest="false"
to the <#Page ... > directive at the top of your aspx file. Or you can modify the web.config to get the same effect right across your web app.
You can't put markup in a textarea. You must HTML-escape any markup characters inside textarea just as you must with any other element.
<textarea><foo> & <bar></textarea>
Although in practice browsers will usually work out what you mean and show any < characters as-is, it's still invalid HTML and non-well-formed XML (presumably this is also the root of your issue in ASP.NET, though without specific code it's difficult to tell).

Categories

Resources