Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 31, 2012 07:14 AM by nagendra.gang
Participant
1970 Points
1395 Posts
Jan 27, 2012 11:35 AM|LINK
Page.ClientScript.RegisterStartupScript(this.GetType(),"clearControls",
"getFileDetailsToHidden( );", true);
This is the way i am calling a javascript function from code behind but how can i call that function with parameters?
All-Star
38344 Points
6989 Posts
Jan 27, 2012 11:42 AM|LINK
You can call using WebMethod. Check below link:
http://www.dotnetcurry.com/ShowArticle.aspx?ID=109
Contributor
2673 Points
552 Posts
Jan 27, 2012 11:46 AM|LINK
Try out below part.
string strval = "hello"; int intval = 1; Page.ClientScript.RegisterStartupScript(this.GetType(), "clearControls","getFileDetailsToHidden(" + "'" + strval + "'"+ "," + intval +");", true);
4141 Points
931 Posts
Jan 27, 2012 11:49 AM|LINK
Try this:
Page.ClientScript.RegisterStartupScript(this.GetType(), "clearControls", "getFileDetailsToHidden('my_value');", true);
OR
Page.ClientScript.RegisterStartupScript(this.GetType(), "clearControls", "getFileDetailsToHidden('" + TextBox1.ClientID + "');", true);
Member
326 Points
131 Posts
Jan 27, 2012 11:54 AM|LINK
its simple.....
try this
"getFileDetailsToHidden( "+URCodeBehindvariable+");", true);
Jan 27, 2012 12:35 PM|LINK
Thanks but after i passed parameter to that function i have assigned that value in a hidden variable and then i call that hidden variable from my code behind and assigned to local variable but the value is null. why?
code behind
--------------------
Page.ClientScript.RegisterStartupScript(this.GetType(), "paramFN1", "getFileDetailsToHidden('" + fileIndex + "','"+FileNames+"','"+FileExtensions+"');", true);
string val=Request.Form["hdnFileIndex"]; string val1=Request.Form["hdnFileNames"];
string val=Request.Form["hdnFileExtensions"];
Javascript
---------------
function getFileDetailsToHidden(pFileIndex,pFileNames,pFileExtensions)
{
document.getElementById('hdnFileIndex').value = pFileIndex; document.getElementById('hdnFileNames').value = pFileNames; document.getElementById('hdnFileExtensions').value = pFileExtensions;
<div></div> }
Jan 30, 2012 06:04 AM|LINK
ssjGanesh Javascript --------------- function getFileDetailsToHidden(pFileIndex,pFileNames,pFileExtensions) { document.getElementById('hdnFileIndex').value = pFileIndex; document.getElementById('hdnFileNames').value = pFileNames; document.getElementById('hdnFileExtensions').value = pFileExtensions; <div></div> }
}
Here, are you getting the values in paramaeters pFileIndex, pFileNames and pFileExtensions ?
Star
10512 Points
1354 Posts
Jan 31, 2012 06:05 AM|LINK
Hi,
Check if hdnFileIndex's ClientID is still 'hdnFileIndex'.
And try this code
protected void Page_Load(object sender, EventArgs e) { string fileIndex = "This is fileIndex"; string FileNames = "FileNames"; string FileExtensions = "FileExtensions"; Page.ClientScript.RegisterStartupScript(this.GetType(), "paramFN1", "getFileDetailsToHidden('" + fileIndex + "','" + FileNames + "','" + FileExtensions + "');", true); string val = Request.Form["hdnFileIndex"]; Response.Write("fileIndex's value: " + val); }
<script type="text/javascript"> function getFileDetailsToHidden(pFileIndex, pFileNames, pFileExtensions) { document.getElementById('hdnFileIndex').value = pFileIndex; document.getElementById('hdnFileNames').value = pFileNames; document.getElementById('hdnFileExtensions').value = pFileExtensions; } </script> <form id="form1" runat="server"> <input id="hdnFileIndex" name="hdnFileIndex" type="text" /><input id="hdnFileNames" type="text" /><input id="hdnFileExtensions" type="text" /> <input id="Submit1" type="submit" value="submit" /> </form>
18 Points
5 Posts
Jan 31, 2012 07:14 AM|LINK
ssjGanesh
Participant
1970 Points
1395 Posts
How to call javascript function with parameter from codebehind?
Jan 27, 2012 11:35 AM|LINK
Page.ClientScript.RegisterStartupScript(this.GetType(),"clearControls",
"getFileDetailsToHidden( );", true);
This is the way i am calling a javascript function from code behind but how can i call that function with parameters?
<div></div>Mark as answer,if it helped U!
Rajneesh Ver...
All-Star
38344 Points
6989 Posts
Re: How to call javascript function with parameter from codebehind?
Jan 27, 2012 11:42 AM|LINK
You can call using WebMethod. Check below link:
http://www.dotnetcurry.com/ShowArticle.aspx?ID=109
www.rajneeshverma.com
Keep Forums Clean || Use Alert Moderators.
Lyra Belaqua
Contributor
2673 Points
552 Posts
Re: How to call javascript function with parameter from codebehind?
Jan 27, 2012 11:46 AM|LINK
Try out below part.
string strval = "hello"; int intval = 1; Page.ClientScript.RegisterStartupScript(this.GetType(), "clearControls","getFileDetailsToHidden(" + "'" + strval + "'"+ "," + intval +");", true);Please don't forget to click "Mark as Answer" on the post that helped you.
Before printing, think about the environment, every 3000 A4 paper costs 1 tree.
Sum8
Contributor
4141 Points
931 Posts
Re: How to call javascript function with parameter from codebehind?
Jan 27, 2012 11:49 AM|LINK
Try this:
Page.ClientScript.RegisterStartupScript(this.GetType(), "clearControls", "getFileDetailsToHidden('my_value');", true);OR
Page.ClientScript.RegisterStartupScript(this.GetType(), "clearControls", "getFileDetailsToHidden('" + TextBox1.ClientID + "');", true);Sumit Pathak
------------------
ThisPost = Helped == True ? "Mark As Answer" : "Elaborate your problem in more details"
dineshchaudh...
Member
326 Points
131 Posts
Re: How to call javascript function with parameter from codebehind?
Jan 27, 2012 11:54 AM|LINK
its simple.....
try this
Page.ClientScript.RegisterStartupScript(this.GetType(),"clearControls",
"getFileDetailsToHidden( "+URCodeBehindvariable+");", true);
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
ssjGanesh
Participant
1970 Points
1395 Posts
Re: How to call javascript function with parameter from codebehind?
Jan 27, 2012 12:35 PM|LINK
Thanks but after i passed parameter to that function i have assigned that value in a hidden variable and then i call that hidden variable from my code behind and assigned to local variable but the value is null. why?
code behind
--------------------
Page.ClientScript.RegisterStartupScript(this.GetType(), "paramFN1", "getFileDetailsToHidden('" + fileIndex + "','"+FileNames+"','"+FileExtensions+"');", true);
string val=Request.Form["hdnFileIndex"];
string val1=Request.Form["hdnFileNames"];
string val=Request.Form["hdnFileExtensions"];
Javascript
---------------
function getFileDetailsToHidden(pFileIndex,pFileNames,pFileExtensions)
{
document.getElementById('hdnFileIndex').value = pFileIndex; document.getElementById('hdnFileNames').value = pFileNames; document.getElementById('hdnFileExtensions').value = pFileExtensions;
<div></div> }
Mark as answer,if it helped U!
Sum8
Contributor
4141 Points
931 Posts
Re: How to call javascript function with parameter from codebehind?
Jan 30, 2012 06:04 AM|LINK
Here, are you getting the values in paramaeters pFileIndex, pFileNames and pFileExtensions ?
Sumit Pathak
------------------
ThisPost = Helped == True ? "Mark As Answer" : "Elaborate your problem in more details"
Zhongqing Ta...
Star
10512 Points
1354 Posts
Re: How to call javascript function with parameter from codebehind?
Jan 31, 2012 06:05 AM|LINK
Hi,
Check if hdnFileIndex's ClientID is still 'hdnFileIndex'.
And try this code
protected void Page_Load(object sender, EventArgs e) { string fileIndex = "This is fileIndex"; string FileNames = "FileNames"; string FileExtensions = "FileExtensions"; Page.ClientScript.RegisterStartupScript(this.GetType(), "paramFN1", "getFileDetailsToHidden('" + fileIndex + "','" + FileNames + "','" + FileExtensions + "');", true); string val = Request.Form["hdnFileIndex"]; Response.Write("fileIndex's value: " + val); }<script type="text/javascript"> function getFileDetailsToHidden(pFileIndex, pFileNames, pFileExtensions) { document.getElementById('hdnFileIndex').value = pFileIndex; document.getElementById('hdnFileNames').value = pFileNames; document.getElementById('hdnFileExtensions').value = pFileExtensions; } </script> <form id="form1" runat="server"> <input id="hdnFileIndex" name="hdnFileIndex" type="text" /><input id="hdnFileNames" type="text" /><input id="hdnFileExtensions" type="text" /> <input id="Submit1" type="submit" value="submit" /> </form>If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
nagendra.gan...
Member
18 Points
5 Posts
Re: How to call javascript function with parameter from codebehind?
Jan 31, 2012 07:14 AM|LINK