Sharepoint Forum

 
Home » Forum » Sharepoint       Ask a questionRSS Feeds

How to assign javascript to C# ?

  Asked By: Pauline Kent         Date: Dec 27, 2009      Category: Sharepoint      Views: 809
 

Is there a way to store javascript variable to C# string variable.
I'm trying to achive this in my asp.net <http://asp.net> web application.

private void Page_Load(object sender, System.EventArgs e)

{

string userName ="Hello : ";

Response.Write("<script> language='javascript'>function AlertBox(){ var
name='Tom';alert('"+userName+"'+name)}</script>");

Response.Write("<script>'"+userName=userName+"'+name<script>");

Response.Write("<input value='Find User' type=button onclick=\"
AlertBox();\" >");

//need be append userName with var name='Tom'...something like
userName+=name;

Label1.Text = userName;//output should be Hello : Tom

}

I know this is not a SharePoint yahoo group question. but later i'm
implementing this functionaytllity in a web part application.

Tagged:          

 

3 Answers Found

 
Answer #1       Answered By: Jonathan Justice          Answered On: Dec 27, 2009       

by using getElementbyID function get the server side control in javascript  and
assign there the value.

 
Answer #2       Answered By: Dhanishta Bapakar          Answered On: Dec 27, 2009       

Try using HtmpInputHidden control. This control can be accessed from both C# as
well as Javascript.

 
Answer #3       Answered By: Easy Tutor          Answered On: Dec 27, 2009       

Hello, this is a good article:

msdn.microsoft.com/.../html
/aspnet-injectclientsidesc.asp

 
Didn't find what you were looking for? Find more on How to assign javascript to C# ? Or get search suggestion and latest updates.


Your Answer
  • Answer should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].