Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1073
  • Last Modified:

javascript method raise event in C# code behind

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
Tom Knowlton
Asked:
Tom Knowlton
3 Solutions
 
P1ST0LPETECommented:
Have a look here, this seems to explain fairly well:
http://www.dev-explorer.com/articles/javascript-trigger-asp-net-events
0
 
Tom KnowltonWeb developerAuthor Commented:
This looks like a good solution, but I would like a few more options.

What about using doPostback or hidden fields?
0
 
BuggyCoderCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
P1ST0LPETECommented:
0
 
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
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
 
Tom KnowltonWeb developerAuthor Commented:
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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now