Solved

javascript method raise event in C# code behind

Posted on 2010-11-30
6
1,039 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:knowlton
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: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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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:knowlton
ID: 34252089
thx
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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 …
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now