Call Server Code Without Postback

  • Thread starter Thread starter Fred W
  • Start date Start date
F

Fred W

I have 2 dependent dropdowns and would like to populate the contents
of the child dropdown dynamically based on the selected item of the
parent.

Pretty standard requirement.

However, can this be done without posting back to the server each time
and without sending all possible data to the client first?

I'm attempting to call a server function, passing a value from the
client.

Here's some pseudocode that describes what I'm attempting:

<HTML>
</HEAD>
<script lang="jscript">
function SetDependentHtmlText(src){
var target = document.getElementById['divTarget'];
//the line below is the key piece of functionality
var newText = <%GetHtmlString(%> src.selecteditem.text <%)%>
target.innerHtml = serverText;
}
</script>
</HEAD>
<body>
<SELECT onchange='GetHtmlFromServer(this)'>
<OPTION>Color</OPTION>
<OPTION>Size</OPTION>
</SELECT>
<DIV id='divTarget'></DIV>
</HTML>

(C#)
string GetHtmlString(string keyValue)
{
if (keyValue = "Color")
return
"<SELECT>" +
"<OPTION>Red</OPTION>" +
"<OPTION>Blue</OPTION>" +
"</SELECT>"
}

- Fred
 
Hi Fred,

To avoid refreshing the whole page, you could probably use the WebService
behavior:

"WebService behavior receives method calls from the client-side script and
sends a request to the Web Service. The results are returned to the client
script, and processing continues. The Web page can then use the information
in whatever context is required, such as updating some portion of page
rendering using DHTML.

"A key feature of the WebService behavior is that it enables client-side
script to access a Web Service without requiring navigation to another URL.
Using the WebService behavior approach, the portions of the page that are
indicated by the user's inputs can be dynamically updated using DHTML,
providing a significant improvement in the browsing experience."

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/webservice/overview.asp

Ken
 
Back
Top