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

Tuesday, September 18, 2007

Application_Error, Global.asax : Exception Handling

When I tried manage exceptions in Application_Error event, sometimes throw an error:

Cannot redirect after http headers have been sent

My trick for avoid this exception:

void Application_Error(object sender, EventArgs e)
{
// handle generic application errors
Exception ex = Server.GetLastError();
SiteHelper.HandleExceptionInLog(ex);
Server.ClearError();
Response.Clear();
Server.Execute("Error.aspx");
}

I read these articles before:
http://blogs.msdn.com/kaevans/archive/2003/07/07/9791.aspx
http://www.codeguru.com/csharp/.net/net_asp/miscellaneous/article.php/c12385/
http://forums.asp.net/t/44586.aspx

It works for me.

Wednesday, January 31, 2007

Validators In AJAX UpdatePanel

For perform the validation into UpdatePanel of Ajax, you need make some tricks...
I made it works, with ASP.NET AJAX Release 1.0.
Just add the following lines in the web.config file:
<pages>

<tagMapping>
<add tagType="System.Web.UI.WebControls.CompareValidator" mappedTagType="Sample.Web.UI.Compatibility.CompareValidator, Validators, Version=1.0.0.0"/>
<add tagType="System.Web.UI.WebControls.CustomValidator" mappedTagType="Sample.Web.UI.Compatibility.CustomValidator, Validators, Version=1.0.0.0"/>
<add tagType="System.Web.UI.WebControls.RangeValidator" mappedTagType="Sample.Web.UI.Compatibility.RangeValidator, Validators, Version=1.0.0.0"/>
<add tagType="System.Web.UI.WebControls.RegularExpressionValidator" mappedTagType="Sample.Web.UI.Compatibility.RegularExpressionValidator, Validators, Version=1.0.0.0"/>
<add tagType="System.Web.UI.WebControls.RequiredFieldValidator" mappedTagType="Sample.Web.UI.Compatibility.RequiredFieldValidator, Validators, Version=1.0.0.0"/>
<add tagType="System.Web.UI.WebControls.ValidationSummary" mappedTagType="Sample.Web.UI.Compatibility.ValidationSummary, Validators, Version=1.0.0.0"/>
</tagMapping>
...
</pages>


I read these articles before:
Links to ASP.NET AJAX 1.0 resources, and answers to some common questions
ASP.NET AJAX Validators

Good Coding.

Monday, December 25, 2006

ASP.NET AJAX Tabbed Dialog

For this Tabbed Dialog, you are going to need a MultiView, 2 View and 2 LinkButton. Of course, you can add more controls. I 'm planning to make a templated control so I would like to receive comments.

I read these articles before:
HTML Tabbed Dialog Widget
Web Parts - How to create a tabbed view

The templates
<asp:scriptmanager id="sm1" runat="server">
</asp:scriptmanager>

<asp:UpdatePanel id="up1" runat="server">
<contenttemplate>
<div class="tabs">
<asp:LinkButton
id="tab0" runat="server" CommandArgument="0" CssClass="tabheader"
OnCommand="SearchTab_Command">Basic Search</asp:LinkButton><asp:LinkButton
id="tab1" runat="server" CommandArgument="1" CssClass="tabheader"
OnCommand="SearchTab_Command">Advanced Search</asp:LinkButton>
</div>
<div class="tabcontent">
<asp:MultiView id="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">
<div class="tabbody">
<asp:Label ID="Label1" runat="server" Text="Tab 1"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Post 1" />
</div>
</asp:View>
<asp:View ID="View2" runat="server">
<div class="tabbody">
<asp:Label ID="Label2" runat="server" Text="Tab 2"></asp:Label>
<br />
<asp:Button ID="Button2" runat="server" Text="Post 2" />
</div>
</asp:View>
</asp:MultiView>
</div>
</contenttemplate>
</asp:UpdatePanel>

The code
<script runat="server" type="text/VB">
Private Sub SwitchCss(ByVal wctl As WebControl)
Dim cc As String = IIf(wctl.CssClass.Equals("tabheader"), "tabheader_active", "tabheader")
wctl.CssClass = cc
End Sub

Protected Sub SearchTab_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
Dim ctl As WebControl

ctl = CType(up1.FindControl(String.Format("tab{0}", MultiView1.ActiveViewIndex.ToString())), WebControl)
SwitchCss(ctl)

MultiView1.ActiveViewIndex = e.CommandArgument

ctl = CType(sender, WebControl)
SwitchCss(ctl)
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If (Not IsPostBack) Then
SwitchCss(tab0)
End If
End Sub
</script>

The CSS
.tabheader {
background-color: #F5F5F5;
color: #C0C0C0;
border: solid 1px #C0C0C0;
}

.tabheader_active {
background-color: #FFFFFF;
color: #608fc8;
border: solid 1px #C0C0C0;
border-bottom: solid 1px #FFFFFF;
cursor:default;
}

.tabs a {
position: relative; width: auto; display:inline;
padding: 2px 4px 2px 4px;
margin: 0 0 0 5px;
font-size:10pt;
}

.tabs a:hover { text-decoration:underline; }
.tabs a.tabheader { color: #666666; }

.tabcontent {
height: 100%; margin-top:2px;
background-color: white;
border: solid 1px #D3D3D3;
}

.tabbody { height: 100%; margin: 9px 9px 9px 9px; }
Google