You must Sign In to post a response.
  • Category: .NET

    Accessing the web method parameter in another method

    below is my code which return name that is entered in textbox in the web method and displays the name current time and date as output now what i need is i only need to pass the name to another method how can i do this

    <script type="text/javascript">
    function ShowCurrentTime() {
    PageMethods.GetCurrentTime(document.getElementById("<%=txtUserName.ClientID%>").value, OnSuccess);
    }
    function OnSuccess(response, userContext, methodName) {
    alert(response);
    }
    </script>

    </head>
    <body>
    <form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
    </asp:ScriptManager>

    <div>
    Your Name :
    <asp:TextBox ID="txtUserName" runat="server" ></asp:TextBox>
    <input id="btnGetTime" type="button" value="Show Current Time" onclick="ShowCurrentTime()"/>
    </div>
    </form>
    </body>

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    [System.Web.Services.WebMethod]
    public static string GetCurrentTime(string name)
    {
    return "Hello " + name + Environment.NewLine + "The Current Time is: "
    + DateTime.Now.ToString();
    }
    now what I need is I need another method only with name that is obtained from WebMethod and on button click I need to display the name with method name how can I do this
  • #767073
    What you want exactly you want to call another method for the button click?
    SRI RAMA PHANI BHUSHAN KAMBHAMPATI

  • #767074
    if you run my current code that I had posted after giving the name in textbox and click on show current time button you can see the name that is given in textbox, current time and the date , now I need to take another method and pass the name that is in web method to the newly taken method and if I click the button I should see the name and method name in the output

  • #767075
    Call a subsequent function in the server side code with an argument of that name
    to get current method name

    [MethodImpl(MethodImplOptions.NoInlining)]
    public static string GetCurrentMethod ()
    {
    StackTrace st = new StackTrace ();
    StackFrame sf = st.GetFrame (1);

    return sf.GetMethod().Name;
    }


    you can use reflection

    using System.Reflection;
    MethodBase.GetCurrentMethod().Name;

    SRI RAMA PHANI BHUSHAN KAMBHAMPATI

  • #767076
    can you show this in my code bacause after implementing this i am still returning the output fro web method only

  • #767093
    public static string GetCurrentTime(string name)
    {
    return "Hello " + name + Environment.NewLine + "The Current Time is: "
    + DateTime.Now.ToString();
    hidname.value = name;
    }

    PageMethods.GetCurrentMethodname(document.getElementById("<%=hidname.ClientID%>").value, OnSuccess);

    [MethodImpl(MethodImplOptions.NoInlining)]
    public static string GetCurrentMethod ()
    {
    StackTrace st = new StackTrace ();
    StackFrame sf = st.GetFrame (1);
    return sf.GetMethod().Name;
    }

    or

    using System.Reflection;
    MethodBase.GetCurrentMethod().Name;

    SRI RAMA PHANI BHUSHAN KAMBHAMPATI


Sign In to post your comments