Solved

javascript method raise event in C# code behind

Posted on 2010-11-30
6
1,057 Views
Last Modified: 2012-05-10
Is there a way a javascript event can raise an event or set some value that the C# code behind can process?

As in __doPostback

or

setting some hidden field?

I just don't remember the mechanics of it.


Please provide working source code for both of the options I listed, or a better way than either one of those is fine.
0
Comment
Question by:Tom Knowlton
[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
6 Comments
 
LVL 10

Expert Comment

by:P1ST0LPETE
ID: 34241802
Have a look here, this seems to explain fairly well:
http://www.dev-explorer.com/articles/javascript-trigger-asp-net-events
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 34241835
This looks like a good solution, but I would like a few more options.

What about using doPostback or hidden fields?
0
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 167 total points
ID: 34242328
another way is using AJAX and Javascript.
we use XMLHTTPRequest object to go to server behind the scenes and call events.

here is an example
http://www.mikesdotnetting.com/Article/40/ASP.NET-and-Ajax-using-XmlHttpRequest
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Assisted Solution

by:P1ST0LPETE
P1ST0LPETE earned 166 total points
ID: 34244375
0
 
LVL 11

Assisted Solution

by:SAMIR BHOGAYTA
SAMIR BHOGAYTA earned 167 total points
ID: 34247557
Hello,

Try this code.

StringBuilder sb = new StringBuilder();
sb.Append("<script language='JavaScript'>");
sb.AppendFormat("window.close")
sb.Append("</script>");
Page.RegisterStartupScript("Test", sb.ToString());

Also try this code.

private void Page_Load(object sender, System.EventArgs e)
{
  if(!IsPostBack)  
 {
       Button1.Attributes.Add("onclick","return confirm('Do u want to postback ?')");
 }
}
0
 
LVL 5

Author Closing Comment

by:Tom Knowlton
ID: 34252089
thx
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

729 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