I render HTML returned from an ajax call and currently uses simple html controls and开发者_JAVA技巧 the string that is returned from the ajax call looks like this:
string s = "<tr><td><a href=\"#\">MyLink</a></td></tr>";
Now, on the click on these links I need to do some processing on the server side to determine where I need to navigate to and for other information. My understanding is that I cannot use <asp:linkbutton />
in this html string I am building.
How do I make a server side call if i don't want to use ajax.
You don't necessarily need to use ASP .NET server controls to enact server-side logic in a post-back. The link for which you manually build the HTML and return in the AJAX call can direct the user to an HttpHandler (or even an aspx page) and pass necessary values to that handler/page on the query string. Then that handler/page can perform its server-side logic and redirect as necessary.
Maybe I've misunderstood the problem? Is there a specific reason why you're looking to use a LinkButton in particular?
Write a javascript function and call it from each link's onlick like this:
<a href="#" onclick="someFunc(this)">My Link</a>
someFunc can then set a hidden input field to the value you want the server to react to. This could be anything from the link element (the text of the link, the value of an attribute you specify in your AJAX response, etc.). At the end of the function, call form1.submit();
function someFunc(link){
var hiddenInput = document.getElementById("ClickedLink");
hiddenInput.value = link.innerText;
form1.submit();
}
Then on the server, in your On_Load in the code behind:
if(ClickedLink.Value != ""){
ProcessLinkClick(ClickedLink.Value);
}
精彩评论