how can we write javascript on .cs file

Posted by Bageshkumarbagi under C# on 11/6/2012 | Points: 10 | Views : 5856 | Status : [Member] | Replies : 2
hi
How can we write javascript code in .cs file. I am creating login page in this page i want after login it will go to previous page .How can i write code for that . plz help me.

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied



Responses

Posted by: Sandhyab on: 11/6/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Use this name space in code behind
System.Web.UI;

Add the below Code to .cs file and Replace your javascript function name in the Place of yourfunction()
ScriptManager.RegisterStartupScript(Page, typeof(Page), "ShowValidation", "javascript:yourfunction();", true);

Thanks & Regards
Sandhya

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Selfwilleddude on: 11/6/2012 [Member] Starter | Points: 25

Up
0
Down
you can use this..
protected void Page_Load(object sender, EventArgs e)

{
btnSubmit.Attributes.Add("onclick", "javascript:myfun();");
}


for example

protected void Page_Load(object sender, EventArgs e)
{
btnSubmit.Attributes.Add("onclick", "javascript:if(confirm('Are you sure go to previous page?')== false) return false;");
}



Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response