• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 662
  • Last Modified:

ASP.NET C# RegisterClientScriptBlock

I want to convert this Javascript on Client page to the Code Behind C# page .....


string strCsharp = "CsharpPage"; //// Only this variable is being passed from Code Behind.. It has to be written on server side when a button is clicked....
            <script language="javascript">
            
            function GetPage()
                  {
                               
                         var frm = document.forms[0];
                         frm.HiddenStudent.value = 'yes';  // Hiddenvariable
                         frm.HiddenGoToPage.value = 'Admin.aspx';
                         frm.HiddenCSHARPVALUE.value = strCsharp;  //value being passed from csharp code behind
                         frm.document.action = 'GotoASPPage.asp';
                         frm.document.submit();
                     
          }
            
0
dotnet0824
Asked:
dotnet0824
  • 3
1 Solution
 
dotnet0824Author Commented:
I am not familiar in writing the Syntax on The server side. Can it be shown
0
 
dotnet0824Author Commented:
C#  code Behind Page

private void Button_click Event
 {
        the script goes here //
}
0
 
bischofb_CRNETCommented:
I'm typing this in off the top of my head, but it should be pretty close to being syntactically correct.
private void Button_click
{
//create a string which has your javascript function in it
string js="function GetPage()";
js += "{"
js += "var frm = document.forms[0];";
js += "frm.HiddenStudent.value = 'yes';"
js +="frm.HiddenGoToPage.value = 'Admin.aspx';";
//concatenate the value you need here
js +="frm.HiddenCSHARPVALUE.value =" + strCsharp;  //value being passed from csharp code behind
js += "frm.document.action = 'GotoASPPage.asp';";
js+="frm.document.submit();";
js += "}";  
//add this to your web page. the first parameter doesn't mean much - just a function name
Page.RegisterStartupScript("AnyNameHere", js, true);
0
 
dotnet0824Author Commented:
Thanks a lot.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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