如何在asp.net c中从我的静态webmethod调用javascript函数# [英] how to call javascript function from my static webmethod in asp.net c#

查看:69
本文介绍了如何在asp.net c中从我的静态webmethod调用javascript函数#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个代码来从我的静态webmethod调用javascript函数。

plz help .......

提前感谢



i need a code to call a javascript function from my static webmethod.
plz help.......
thanks in advance

[System.Web.Services.WebMethod]
       public static string password(string UserId, string UserName, string Password, string ConPassword, string EmailId, string Country, string date)
       {
           TextBox TxtUserId = new TextBox();
           TextBox TxtPassword = new TextBox();
           //TxtUserId.Text = "";
           //TxtPassword.Text = "";
           string flag = "";
           date = DateTime.Now.ToString("dd/MM/yyyy");
           ScriptManager MyScriptManager = new ScriptManager();
           MyScriptManager = (ScriptManager)HttpContext.Current.Session["Script"];
           Page page1 = HttpContext.Current.CurrentHandler as Page;
           TxtUserId = (TextBox)HttpContext.Current.Session["TxtUserId"];
           TxtPassword = (TextBox)HttpContext.Current.Session["TxtPassword"];
           try
           {
              if (Password.Trim().Replace(" ", "") != ConPassword.Trim().Replace(" ", ""))
               {
                   flag = "false1";
                   //Password.Text = "";
                   return flag;
               }

               else
               {
                   page1.ClientScript.RegisterStartupScript(page1.GetType(), "id", "GetUserIdMessage()", true);     //Message("Hi")  should be printed
                   MyFunctions Functions = new MyFunctions();
                   Functions.insertLogin("insert into UserLogin values('" + UserId.Trim().Replace(" ", "") + "','" + UserName.Trim().Replace(" ", "") + "','" + Password.Trim().Replace(" ", "") + "','" + EmailId.Trim().Replace(" ", "") + "','" + Country.Trim().Replace(" ", "") + "','" + date.Trim().Replace(" ", "") + "')");
                   flag = "true";
                   return flag;
               }
           }

           catch (Exception ex)
           {
            return ex.Message.ToString();
           }
       }

推荐答案

不要在WebMethod中调用JavaScript函数。你可以做的是,只需要从方法返回任何值,如果需要,然后在Ajax成功之内,调用另一个JavaScript函数。这很容易。
Don't call a JavaScript function inside a WebMethod. What you can do is, just return from the method with any values if needed and then inside Ajax success, call the other JavaScript function. This is very easy.


这篇关于如何在asp.net c中从我的静态webmethod调用javascript函数#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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