Click here to Skip to main content
15,885,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HTML
<script type="text/javascript">

       function Enterkey1() {
      var UserId = document.getElementById("<%=TxtUserid.ClientID%>").value;
      var UserName = document.getElementById("<%=TxtUserName.ClientID%>").value;
      var Password = document.getElementById("<%=TxtPassword.ClientID%>").value;
      var ConPassword = document.getElementById("<%=TxtConPassword.ClientID%>").value;
           var EmailId = document.getElementById("<%=TxtEmailId.ClientID%>").value;
           var Country = document.getElementById("<%=TxtCountry.ClientID%>").value;
           var date = '0';

                   PageMethods.password(UserId,UserName,Password,ConPassword,EmailId,Country,date,onSuccess);
               return false;
           }


#I am Passing Parameters as controls's values Using PageMethods.[WebMethod-Name]
**** Can I Pass the Control from JavaScript to my WebMethods....
For Exmaple, I want to pass my TextBox from javascript's PageMethods to my c# WebMethod function....to store "Blank" in <password> and <confirm password=""> if it mismatches in my c# page....
Is It Possible????

Millions of Thanks in advance....



Below is my c# code
C#
[System.Web.Services.WebMethod]
        public static string password(string UserId, string UserName, string Password, string ConPassword, string EmailId, string Country, string date)
        {
            string flag = "";
            date = DateTime.Now.ToString("dd/MM/yyyy");
            try
            {
               if (Password.Trim().Replace(" ", "") != ConPassword.Trim().Replace(" ", ""))
                {
                    flag = "false1";
                    //Password.Text = "";
                    return flag;
                }

                else
                {
                    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();
            }
        }
Posted
Updated 11-Aug-15 21:08pm
v2
Comments
ZurdoDev 12-Aug-15 7:26am    
Are you asking if you can pass the object to the parameter instead of just the object's value? No, you cannot do that. And wouldn't want to anyway.
harshil gandhi 12-Aug-15 7:31am    
Thanks for ur reply...@RyanDev
harshil gandhi 12-Aug-15 7:32am    
if i want to set set the textbox value to be changed with the web controls in web method....how to do that?
ZurdoDev 12-Aug-15 7:34am    
I don't understand. The textbox is a webcontrol so what exactly do you mean?
harshil gandhi 11-Jun-16 2:51am    
No.. actually, thats impossible.. we cannot access the values of the actual textbox... insted we can get the values from the textbox from javascript and call the webMethod and pass those textbox values to webMethod... Thanks.. I forgot this logic.. Thanks @RyanDev... Cheers

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900