Solved

javascript method raise event in C# code behind

Posted on 2010-11-30
6
1,045 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASCX file or a newer alternative? 1 40
convert html to string 6 38
imap mails 1 25
insert value of checklistbox checked 4 32
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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.…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

792 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