Message.Show() does not work after deployment in ASP.Net

Last Reply on Apr 07, 2017 02:27 AM By AnandM

Posted on Apr 03, 2017 02:54 AM

hi ,

I asked you something that you find belowe link

dialogbox working in localhost But does not work when project deploy to hosting.

http://www.aspforums.net/Threads/124278/Execute-code-based-on-Yes-No-Message-Box-Button-click-using-C-and-VBNet-in-ASPNet/

Results 1 - 5 of 10 12
Posted on Apr 03, 2017 09:00 AM Modified on on Apr 03, 2017 09:00 AM

Hi alya14,

Refer the below link.

http://stackoverflow.com/questions/28339010/my-message-box-in-asp-net-does-not-work-on-the-server-so-what-is-it-used-for

The System.Windows.Forms.MessageBox and System.Windows.MessageBox classes are for displaying message boxes in Windows forms applications and Windows WPF applications, i.e. client applications.

If you try to use those in a web application, it would show the message box on the web server, not on the client computer. As a web application runs in an account without a user interface (no logged in user), there would be nowhere to show the message box.

In a web appication you would use the window.alert or window.confirm methods in Javascript to show a simple popup message. If you search for message box web server control you will find several examples of web server controls implementations and alternatives.

 



Posted on Apr 04, 2017 03:14 AM Modified on on Apr 06, 2017 05:37 AM

Hi alya14,

You can use javascript confirmation message box for the same which will work in Hosted Site too.

I have created a sample which full your requriement you need to modify the code according to your need.

HTML

<div>
    <asp:GridView ID="GridView1" runat="server">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:CheckBox ID="chkboxid" runat="server" onclick="toggleSelectionGrid(this);" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <br />
    <asp:Button ID="Button1" runat="server" OnClick="Query_Click" Text="QUERY" />
    &nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Button ID="btnSendMail" OnClick="SendMail" runat="server" Text="SEND" />
    <br />
</div>
<div>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
        function toggleSelectionGrid(source) {
            var isChecked = source.checked;
            $("#GridView1 input[id*='chkboxid']").each(function (index) {
                $(this).attr('checked', false);
            });
            source.checked = isChecked;
        }

        $(function () {
            $('[id*=btnSendMail]').click(function () {
                var checkbox = "";
                $('[id*=GridView1] tr').each(function () {
                    var row = $(this).closest('tr');
                    var chkboxid = row.find('[id*=chkboxid]');
                    if ($(chkboxid).is(':checked')) {
                        checkbox = chkboxid;
                    }
                });
                if ($(checkbox).is(':checked')) {
                    var row = $(checkbox).closest('tr');
                    var country = row.find('td').eq(3).html();
                    var value = confirm('Do u want the start service for ' + country + '?');
                    if (value) {
                        return true;
                    }
                    else {
                        alert('You Have Stopped the Service');
                    }
                }
                else {
                    alert('Please Select AtLeast one checkbox from GridView');
                }
                return false;
            });
        });
    </script>
</div>

C#

protected void Query_Click(object sender, EventArgs e)
{
    DataTable dt = new DataTable();
    dt.Columns.AddRange(new DataColumn[] { new DataColumn("Id"), new DataColumn("Name"), new DataColumn("Country") });
    dt.Rows.Add(1, "John Hammond", "United States");
    dt.Rows.Add(2, "Mudassar Khan", "India");
    dt.Rows.Add(3, "Suzanne Mathews", "France");
    dt.Rows.Add(4, "Robert Schidner", "Russia");
    //Bind your Gridview with database records.
    GridView1.DataSource = dt;
    GridView1.DataBind();
}

protected void SendMail(object sender, EventArgs e)
{
    //Proceed with your further Process.
    ClientScript.RegisterStartupScript(this.GetType(), "Start", "alert('Your Service Started')", true);
}

VB.Net

Protected Sub Query_Click(sender As Object, e As EventArgs)
	Dim dt As New DataTable()
	dt.Columns.AddRange(New DataColumn() {New DataColumn("Id"), New DataColumn("Name"), New DataColumn("Country")})
	dt.Rows.Add(1, "John Hammond", "United States")
	dt.Rows.Add(2, "Mudassar Khan", "India")
	dt.Rows.Add(3, "Suzanne Mathews", "France")
	dt.Rows.Add(4, "Robert Schidner", "Russia")
	'Bind your Gridview with database records.
	GridView1.DataSource = dt
	GridView1.DataBind()
End Sub

Protected Sub SendMail(sender As Object, e As EventArgs)
	'Proceed with your further Process.
	ClientScript.RegisterStartupScript(Me.[GetType](), "Start", "alert('Your Service Started')", True)
End Sub

ScreenShot


Posted on Apr 06, 2017 04:56 AM

at firslty thank you for follow-up ,

it's working , But I want to if multiple checking

throw alert "just check one"

and I want catch checking value so (Country column)

and modified dialog box Do u want the start service for India ?


Posted on Apr 06, 2017 05:03 AM
alya14 says:
and I want catch checking value so (Country column)

 can you explain above statement in more breif?