Client Callbacks Using Master Pages

I follow this example: http://msdn.microsoft.com/en-us/library/ms178210.aspx

And I can make it work with only one page and code, but when I add the main page, the examples do not work properly. On my main page, I have a chapter content section and a body content section. Nothing unusual.

How to make customer callbacks using master pages?

+3
source share
2 answers

A more scalable approach is to use the following syntax (replace ResultsSpan with the aspx panel) ...

function LookUpStock()
{
    var lb = document.getElementById('<%=ListBox1.ClientID%>');
    var product = lb.options[lb.selectedIndex].text;
    CallServer(product, "");
}

function ReceiveServerData(rValue)
{   
    document.getElementById('<%=ResultsSpan.ClientID%>').innerHTML = rValue;
}

Thus, if the name (or actual page) of MasterPage changes, the code will still work.

ASP.NET <% =% > .

, . , , , : MASTERPAGEPREFIX_CONTAINERCONTOLNAME_ListBox1, .

" " - ASP.NET

+1

.

, ContentPage MasterPage:

function LookUpStock()
{
    var lb = document.getElementById("MASTERPAGEPREFIX_" + "ListBox1");
    var product = lb.options[lb.selectedIndex].text;
    CallServer(product, "");
}

function ReceiveServerData(rValue)
{   
    document.getElementById("MASTERPAGEPREFIX_" + "ResultsSpan").innerHTML = rValue;
}
-1

Source: https://habr.com/ru/post/1762226/


All Articles