Showing posts with label AJAX. Show all posts
Showing posts with label AJAX. Show all posts

Thursday, October 30, 2008

Recovering lost AJAX Control Toolkit Controls in VS2008

When using Visual Studio 2008 and you have the AJAX Control Toolkit installed you might have experienced that your AJAX Controls disappear from the Toolbox. If you right-click on a Tab in the Toolbox and select Show All, you'll see that the controls are still there; however, they are all greyed out. This happens when using Visual Studio 2008 and targeting .Net Framework 2.0 in both Web Application Projects and Web Sites. You can resolve this by doing the following for Web Applications and Web Sites.
Web Solutions:
1. Click Project.
2. Select ProjectName Properties.
3. Under Target Framework, change it from .NET Framework 2.0 to .NET Framework 3.5.
4. Click Save.

Web Sites:
1. Click Website.
2. Select Start Options.
3. Select Build and under Target Framework, change it from .NET Framework 2.0 to .NET Framework 3.5.
4. Click OK.

Monday, January 28, 2008

How-To Auto Collapse Microsoft AJAX Collapsible Panel

Here's a quick tip on how to automatically collapse a Collapsible Panel through code. This is useful in a situation such as having a Collapsible Panel that contains a few controls used in data entry and once the user has entered the data and clicked on a button to submit their data you want the panel to collapse automatically.

You would think that just performing a (control name) CollapsiblePanelExtender1.collapse = True would collapse the panel; however, this will not work by itself. This is due to the fact that there is a short delay between the first rendering of the page and the running of the Javascript to modify it. To have the panel collapse you will need to add one more line, so your code will look like this.

CollapsiblePanelExtender1.Collapsed = True;
CollapsiblePanelExtender1.ClientState = "true";
You can also prevent the PopControlExtender from briefly showing controls it contains by placing the controls within a Panel Control and setting the Panel Control's visibility style to hidden. This will stop the annoying flickering that happens when the page is first rendered.

Thursday, June 21, 2007

More Useful C# Code Snippets

Display Pop-Up Error Messages In An ASP.NET Application

I came across an issue in which someone needed to pop-up a Window to display an error message to users in their ASP.NET application. I did some research and discovered this very handy bit of code that will display a JavaScript Alert MessageBox that you can populate with the error message.

Below is an example I created that purposely causes a DivisonByZero Exception and displays this in a JavaScript Alert MessageBox.


int num1 = 10;
int num2 = 0;
int result;

try
{
result = n1 /n2;
}
catch (DivideByZeroException ex)
{
DisplayErrorMsg(ex);
}


private void DisplayErrorMsg(Exception ex)
{
RegisterStartupScript(Guid.NewGuid().ToString(),
string.Format("<script language='Javascript'>alert('{0}');</script>", ex.Message));
}

Populate The Display Text Of A CollapsiblePanel Control From A File

I had the need to populate the text to be displayed in an ASP.NET AJAX CollapsiblePanel Control via a text file as opposed to just embedding the text between a tag of my Content Panel. I had to display a large amount of text that displayed some Terms and Conditions and there was just to much to put between the tags. Besides it really would make the code ugly having all of that text embedded.

The solution I decided to go with was to create a Web User Control and fill the control with the text to be displayed. Then I went back to the page that I was going to display this text on and dropped the Custom Control inside of my CollapsiblePanel's ContentPanel. I then went into the HTML source of the page and surrounded the ContentPanel with a Div tag and sat the height, overflow, and background color.






<ajaxToolkit:CollapsiblePanelExtender ID="CollapsiblePanelExtender1" runat="server"
TargetControlID="ContentPanel"
ExpandControlID="TitlePanel"
CollapseControlID="TitlePanel"
Collapsed="false"
TextLabelID="Label1"
ExpandedText="(Hide Details...)"
CollapsedText="(Show Details)"
ImageControlID="Image1"
CollapsedImage="images/expand.jpg"
ExpandedImage="images/collapse.jpg"
SuppressPostBack="true">
</ajaxToolkit:CollapsiblePanelExtender>


<asp:Panel ID="TitlePanel" runat="server" Height="30px" Width="545px">
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/expand.jpg"/>
Terms and Conditions
<asp:Label ID="Label1" runat="server" Text="Label">(Show Details ...)</asp:Label>
</asp:Panel>
<asp:Panel ID="ContentPanel" runat="server" Height="0px" Width="545px">                                
<div style="height:150px;overflow:scroll;background-color:ButtonFace;" >
<uc2:Terms ID="Terms1" runat="server" /></div>
</asp:Panel>