Solved

javascript method raise event in C# code behind

Posted on 2010-11-30
6
1,042 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb.net dynamic formulas in runtime 11 74
Anyway to make "All" the default in the dropdown? 6 36
SQL Exceptions 3 43
IIS Authorization for Web Service 2 46
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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