简体   繁体   中英

Call javascript function with parameters and read the return values in page load

I have javascript function in default.aspx like this:

 function ReadValue(Name) {
    Return value;
 }

Now from pageLoad method, I want to pass parameter and get the return value to server side variable.

To send data from the client to the server, you have to ... send data from the client to the server. :-) Typically, you do that with Ajax , although there are other ways as well (doing a standard form POST , or even doing a GET of some kind although if your server is going to act on the information by changing server state, you shouldn't use GET ).

another way is by putting the values in sever side controls for exmaple in jquery you can do something like this:

function pageLoad(sender, args) {
$("#txtMyTextBoxID").val('my value')

}

aspx:

<asp:TextBox ID="txtMyTextBoxID" runat="server" ClientIDMode="Static"></asp:TextBox>

I would say the best idea is to make a Javascript function and make a server side Hiddenfield. Access that hidden field and store your values (comma delimited) in your hiddenfield. and access it on page load.

I do it this way.

<asp:HiddenField ID="hdn" runat="server" />
document.getElementById("<%= hdn.ClientID%>").value = "your value";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM