[已解决]来自服务器端的Javascript警报 [英] [Solved] Javascript alert from server side

查看:83
本文介绍了[已解决]来自服务器端的Javascript警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



存储数据时,我必须显示一个消息框.
我已使用此代码...

当我在演示网站上对其进行测试时,它运行良好.但是,当我将其应用到Web应用程序中时,它没有显示任何错误,但消息框没有弹出.

Hi,

I have to show a message-box when the data gets stored.
I have used this code...

It worked fine when i tested it with demo website...But when i applied it in my web-application, it showed me no error but also the message-box didn''t popup.

protected void btnok_Click(object sender, EventArgs e)
      {
          try
          {
              string _status = "Pending";
              //bool _result = _objVreg.insertdata(_strTablename, txtname.Text.ToString(), txtmobileno.Text.ToString(), txtcompany.Text.ToString(), txtpurpose.Text.ToString(), ddldepartment.SelectedItem.ToString(), ddlcontacperson.SelectedItem.ToString(), txtcity.Text.ToString(), System.DateTime.Now, Session["UserName"].ToString(), "", _status);
              bool _result = _objVreg.insertdata(_strTablename, txtname.Text.ToString(), txtmobileno.Text.ToString(), txtcompany.Text.ToString(), txtpurpose.Text.ToString(), ddlbranch.SelectedValue.ToString(), ddldepartment.SelectedValue.ToString(), ddlcontacperson.SelectedValue.ToString(), txtcity.Text.ToString(), System.DateTime.Now, "", "", _status, txtluggage.Text.Trim());
              if (_result == true)
              {
                  Alert.Show("Record Added Successfully");

              }
              else
              {
                  lblMsg.Text = "Record Not Added, Please Try Again";
              }
          }
          catch (Exception ex)
          {
              Response.Write(ex.Message);
          }
      }



我添加了一个名为"Alert.cs"的类,该类显示以字符串形式传递的所有弹出窗口.
班级是



I have added a class named "Alert.cs" which shows any popup passed as string.
The class is

public static class Alert
   {

       /// <summary>
       /// Shows a client-side JavaScript alert in the browser.
       /// </summary>
       /// <param name="message">The message to appear in the alert.</param>
       public static void Show(string message)
       {
           // Cleans the message to allow single quotation marks
           string cleanMessage = message.Replace("'", "\\'");
           string script = "<script type=\"text/javascript\">alert('" + cleanMessage + "');</script>";

           // Gets the executing web page
           Page page = HttpContext.Current.CurrentHandler as Page;

           // Checks if the handler is a Page and that the script isn't already on the Page
           if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
           {
               page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script);
           }
       }

   }



请指导我...

更新:
OP自己解决了该问题,并将其发布为答案之一.



Please guide me...

UPDATE:
OP resolved it by himself and posted it as one of the answer.

推荐答案

http://stackoverflow.com/questions/3831366/display-a-yes-no-alert-box-in-c-code-behind [ ^ ]

http://madskristensen.net/post/JavaScript-AlertShow%28e2809dmessagee2809d% 29-from-ASPNET-code-behind.aspx [ ^ ]
http://stackoverflow.com/questions/3831366/display-a-yes-no-alert-box-in-c-code-behind[^]

http://madskristensen.net/post/JavaScript-AlertShow%28e2809dmessagee2809d%29-from-ASPNET-code-behind.aspx[^]


已解决...我想我遇到了问题,因为页面正在回发..
我只是在保存后重定向页面,然后将querystring值传递给它..并在加载querystring值时对其进行了检查...

然后将弹出式窗口加载到重定向页面上.在这里工作正常...
Its solved...i guess i was getting the problem because the page was getting post back ..
I simply redirected the page after save and passed a querystring value to it..and checked it at load the querystring value...

and put the popup at load of the redirected page..it worked fine there...


这篇关于[已解决]来自服务器端的Javascript警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆