Possible Duplicate:
Couldn’t find any way of displaying a message box in Visual Webpart 2007 (User Control)

I have been working on SharePoint 2007 for more then a year but still don't have enough knowledge for developing webparts and would like to know followings,

  • Ways of creating Webparts in SharePoint 2007 and which one is best and why (I am aware of webparts that inherits from System.Web.UI.Controls and Visual Webparts (user controls within a webpart))
  • Ways of displaying Message Box in a WebPart without a postback and which one is assumed as best practice (I did tried creating a div and then displaying it using HttpContext.Current.Response.Write and a string builder to build a div and some scripts to display message box)

I would like only highly recommended tutorial links please (not the first one on first page that comes on Google listing) :) !

  • 1
    Loved your quote "not the first one on first page that comes on Google listing" :D :D Nov 16, 2012 at 9:42

2 Answers 2


I created a update panel and added my control in it, then using JavaScript I am catching end request of update panel and then displaying a message box, I have been looking for this solution since ages.

 <script type="text/javascript"> 
   // if you use jQuery, you can load them when dom is read.
   $(document).ready(function () {
       var prm = Sys.WebForms.PageRequestManager.getInstance();    


    function InitializeRequest(sender, args) {

    function EndRequest(sender, args) 

now you can display a message box or any other thing you want to do.

Hope it helps :) as I couldn't find any related post or tutorial on internet even after 7 days of search.


webparts can be done as you described, for ascx is easier for the design team to ammend. I prefer not the ascx and belive css should be sufficent.

the webparts that i prefer are located here:


it outlines the recommended way to produce it (best practice). I would also have a base class that you can inherit the webpart from. In the base class you can add the webpart settings and pass the values to the inherited webpart.

for visual webpart I would only think that its easier for the designer perspective to edit the ascx without the need to change code. I would guess its more of an OOD/OOP method.

there are limmitiations to visual webpart as outlined here:

Visual web parts don't support replaceable parameters. For more information, see Replaceable Parameters.

User controls or visual web parts can't be dragged and dropped or copied onto visual web parts. This action causes a build error.

Visual web parts don't directly support SharePoint server tokens such as $SPUrl. For more information, see "Token Restrictions in Sandboxed Visual Web Parts" in the topic Troubleshooting SharePoint Solutions.

Visual web parts in a sandboxed solution occasionally get the error, "The sandboxed code execution request was refused because the Sandboxed Code Host Service was too busy to handle the request." For more information about this error, see this post in the SharePoint Developer Team Blog.

Server-side JavaScript debugging isn't supported in Visual Studio, but client-side JavaScript debugging is supported.

Although you can add inline JavaScript to a server-side markup file, debugging isn't supported for breakpoints added to the markup. To debug JavaScript, reference an external JavaScript file in the markup file, and then set the breakpoints in the JavaScript file.

Debugging of inline ASP.NET code must be done in the generated code file instead of in the markup file.

Visual web parts don't support the use of the <@ Assembly Src= directive.

SharePoint web controls and some ASP.NET controls aren't supported in the SharePoint sandboxed environment. If unsupported controls are used on a visual web part in a sandboxed solution, the error, "The type or namespace name 'Theme' does not exist in the namespace 'Microsoft.SharePoint.WebControls'" appears.


as for displaying a Message Box in a WebPart without a postback, I dont think is possible... serverside ;) but is using javascript using the alet("helloWorld").

like so in code:

ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "test", "alert('helloWorld');");

In javascript code you need to return false for alert function so it would give no postback otherwise it would be set to default return true and perfome a postback.

If you want to show hide a custom message box the is tied to the page then you just need to load panel during pageload or createchildcontrols and set visibility to false, have everything in panel that you want to display as a message. Register a clickevent on whatever it is and that would set the panel to visible, you can change the css to make it more appealing ;).

hope it helps :)

  • Can You give a sample code ?
    – Grzegorz Z
    Nov 16, 2012 at 11:49
  • what part weould you like the sameple code?
    – Ali Jafer
    Nov 16, 2012 at 12:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.