0

I render HTML returned from an ajax call and currently uses simple html controls and 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.

2
  • Do you have access to change the HTML coming from the AJAX? Commented Jan 26, 2011 at 20:53
  • Yes, I do have access to change the HTML Commented Jan 26, 2011 at 20:54

2 Answers 2

1

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?

Sign up to request clarification or add additional context in comments.

Comments

0

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);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.