Wednesday, December 31, 2008

ASP.Net page directives

@ Page directive attributes
The following table lists some of the commonly used attributes available with the @ Page directive in parsing and compiling ASP.NET pages.
@ Page directive attributes
Attribute Description
AutoEventWireup Specifies whether the page's events are autowired (attribute set to True ) or not (set to False ).
CodeBehind Provides the name of the compiled file that contains the class associated with the page. This is used at design time, not at run time. For example, if you have a Web Forms page called Classic, the designer will specify Classic.aspx.vb as the CodeBehind attribute's value for Visual Basic.
CodePage Supplies the code page value for the response. You don't need to set this attribute if you are using the default code page of the web server on which the page will run. Otherwise you should enter the code page for the computer on which you created the page.
Culture Specifies the cultural setting for the page, in other words the language, calendar, and cultural conventions of a particular country or region, for instance fr-CH for Swiss French.
Debug Indicates whether the page should be compiled using debug symbols (attribute set to True ) or not (set to False ).
EnableSessionState Specifies the session-state requirements for the page. If session state is enabled, the value is True (this is the default). To indicate that the session state can be read but not modified, you specify ReadOnly as the value. To disable session state, you specify False. The values are not case sensitive.
EnableViewState Indicates whether view state is maintained across page requests (attribute set to True, which is the default) or not (set to False ).
Inherits Specifies a code-behind class for the page to inherit. You can supply any class derived from the Page class.
Src Defines the source filename of the code-behind class to dynamically compile when the page is requested. The programming logic for your page can either be in such a code-behind class or in a code declaration block in the .aspx file.
Trace Indicates whether tracing is enabled (attribute set to True ) or not (set to False ).

Friday, November 7, 2008

Show message when the update in gridview throws error

public void showmessage(string strMessage)
{
//String strScript = "" ;

//if(! ClientScript.IsStartupScriptRegistered("clientScript"))
// ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript", strScript);
Label lbl = new Label();
lbl.Text = "";
// add the label to the page to display the alertbox
Page.Controls.Add(lbl);

}

protected void gvUsers_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
if (e.Exception != null)
{
string[] s= e.Exception.StackTrace.ToString().Split(new char[]{'\n'});
string errormessage = String.Format("Exception while Updating: {0}
{1}", e.Exception.Message, s[1]);
e.ExceptionHandled = true;
errormessage = "Violation of Primay key occured";
showmessage(errormessage);

}
}

Show Message in ASP.Net 2.0

public void showmessage(string strMessage)
{
//String strScript = "" ;

//if(! ClientScript.IsStartupScriptRegistered("clientScript"))
// ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript", strScript);
Label lbl = new Label();
lbl.Text = "";
// add the label to the page to display the alertbox
//Page.Controls.Add(lbl);

}