Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Code Behinde Function!

Posted on 2004-10-13
2
Medium Priority
?
363 Views
Last Modified: 2006-11-17
Hi All,
i need to know how to call a function in the code behinde(server side) from the client side(html part) in asp.net using vb.net???
any comment will be very helpful
thanx in advanced.
samjav
0
Comment
Question by:samjav
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
ihenry earned 150 total points
ID: 12295665

If you mean make a direct method call to a server-side function from client-side javascript, it would be more appropriate to say "force a postback from client javascript". Read this article
How postback works in ASP.NET
http://www.xefteri.com/articles/dec102002/default.aspx

If you mean to call code-behind function from aspx or using inline code you can use old school asp Response.Write shortcut like so
<% CallToMethod1() %>, where CallToMethod1 is a function defined in code-behind.
0
 
LVL 5

Assisted Solution

by:stumpy1
stumpy1 earned 150 total points
ID: 12297248
Here is an example of how you would do it on an aspx page to call a code-behind function to create a file:

Lets say that the function that you need to call in the code behind is for a linkbutton called CreateFile_Click

Then In the header part of the HTML for the aspx page you need to declare the javascript to call you code-behind function (ie. CreateFile)
<script language="javascript">
<!--
function CreateFile()
{
      fileName = prompt('Type the name of the file you want to create:','');
      if ((fileName) && (fileName!=""))
      {
            document.forms['BrowseFiles'].elements['funcParam'].value = fileName;
            __doPostBack('CreateFile', '');
      }
}
// -->
</script>
This uses the javascript __doPostBack function that is created by asp.net to postback to the CreateFile_Click function in the code-behind.

Then in the HTML on the page inside your form you will need additional code such as the following:

<input id="funcParam" type="hidden" runat="server">
...
<A href="javascript:CreateFile();"><IMG height="28" alt="Create a new text file" src="./Images/NewFile.gif" width="28" border="0">
</A>
<asp:linkbutton id="CreateFile" onclick="CreateFile_Click" Runat="server" Visible="False"></asp:linkbutton>

Notice that there is a linkbutton control that is not visible that is the actual control that we are posting back to too do the work. Ie. Clicking on the <A href... link calls the clientside javascript function which sets the value of a hidden field. The Javascript function then uses the automatically generated client side javascript function to perform the postback to the server side function for the linkbutton control (CreateFile_Click)

I hope this helped.
PS. This is paraphrased from the Wrox book "ASP.NET Website Programming, Problem - Design - Solution"
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question