Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I almost tried everything I could to display a nice message box in user control (.ascx) or code behind, but I failed miserably,

Can anyone find me a tutorial in context to what I need and will 100% work please ?

Until now I tried Ajax Modal Popup and JavaScript but it breaks my "visual" webpart without any error, also if you can explain how can I use your suggested tutorial.

.ascx file

<%@ Assembly Name="Uk9999.Webparts.MyWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=678d049e0f7e2b28" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyWebPartUserControl.ascx.cs"
    Inherits="UK9999.Webparts.MyWebPart.MyWebPartUserControl" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<div class="MainTable" style="font-family: calibri, verdana, sans serif">
    <div style="width: 100%">
        <div style="float: left; width: 45%; ">

There's more controls and then one update panel which is working fine.

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <div align="center" style="color:#*****">
                        <asp:Label ID="lbl1" ....

then in webpart class I am doing this

  public class MyWebpartClass: BaseWebPart
    {
        private const string _ascxPath = @"~/_ControlTemplates/MyWebpartClass/MyWebpartClassUserControl.ascx";

        private UserControl control;
        private ImageButton imagebutton;
        private Button btn;

        protected override void CreateChildControls()
        {
            try
            {
                base.CreateChildControls();

                control = (UserControl)Page.LoadControl(_ascxPath);
                Controls.Add(control);

                btn = (Button)this.control.FindControl("btnCalculate");
                imagebutton= (ImageButton)this.control.FindControl("btnSendEmail");


                btn.Click += new EventHandler(btn_Click);

Now in

protected void btn_Click(object sender, EventArgs e)
        {// I want to display a message box at the moment its using this.Page.Unload += event for displaying a div which does work but does a page refresh..}

I changed controls names so dont get confused because of that

Now also if I try to add JavaScript in it before first div e.g.

<script runat="server">
   void Page_Load(object sender, EventArgs e) {
      Button1.Attributes.Add("onclick",
           "javascript:alert('ALERT ALERT!!!')");
   }
</script>

it displays a blank screen, no errors at all. same thing happens when I try this Ajax Modal Popup. I also tried different other tutorials but non of them actually works.

share|improve this question
    
If you want to email the code to my email on profile I can take a look for you, see what you are trying to do, and make a proper suggestion. It all really depends how and when you want the popup. Would love to help. –  Hugh Wood Nov 22 '12 at 16:16
    
@HughWood would love to do that, but because of company policy I can't pass this code to anyone, however its simply too large to change IDs name and that otherwise I would, however I try to add few bits in my question –  Muhammad Raja Nov 22 '12 at 16:24
    
What do you want the popup to do and say? You could bind a javascript function to the button client side, and do it that way, I can do an example of that if it's suitable. –  Hugh Wood Nov 22 '12 at 16:38
    
Just a message box, I already tried what your saying but then My webparts shows nothing but blank screen without any errors. –  Muhammad Raja Nov 22 '12 at 16:40
    
Can you create a JSFiddle showing how you adding the popup? Then we can work on it. Maybe copy some of the html involved, and recreate a simpler version there? I finish here in about an hour but I can be on all evening GMT time. JSfiddle.net –  Hugh Wood Nov 22 '12 at 16:42

2 Answers 2

Why dont you use OnClientClick property of Button? See this MSDN documentation for more information, and also you can use js as you want in ascx

share|improve this answer
up vote 0 down vote accepted

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();    
       prm.add_initializeRequest(InitializeRequest);
       prm.add_endRequest(EndRequest);

    });        

    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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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