Pulling results from CodeBehind file into JavaScript

Last post 07-17-2007 1:26 PM by XanaLyoko. 7 replies.

Sort Posts:

  • Pulling results from CodeBehind file into JavaScript

    07-17-2007, 11:17 AM
    • Loading...
    • XanaLyoko
    • Joined on 07-03-2007, 12:07 PM
    • Posts 68

    In my code behind files I have this:

    public void test()
        {
            MTConnection con = MTConnection.CreateConnection(new Credential(new Context("ClearQuest - Boise", "Version 2.0", Micron.Application.Context.Environments.Production), "DSSPROD", Credential.DataSourceTypes.MSSQL, Credential.DataSourceProviders.Odbc));

            string sqltest = " select T1.dbid,T12.systemname AS 'ParentSystem',T1.systemname,T1.systemstate,T1.features,T3.name,T4.stakeholder,"+
                             " T4.fldcolumn_1,T1.systemwebpage,T1.description from ( ( ( ( ( ( ( ( CQ_ADMIN.micronsystem T1 INNER JOIN"+
                             " CQ_ADMIN.microngroup T6 ON T1.primarysupportgroup = T6.dbid ) INNER JOIN CQ_ADMIN.securitygroups T7 ON T1.secuirtygroup"+
                             " = T7.dbid ) LEFT OUTER JOIN CQ_ADMIN.parent_child_links T12mm ON T1.dbid = T12mm.child_dbid  and 16778862 ="+
                             " T12mm.child_fielddef_id  ) LEFT OUTER JOIN CQ_ADMIN.micronsystem T12 ON T12mm.parent_dbid = T12.dbid  )"+
                             " LEFT OUTER JOIN CQ_ADMIN.parent_child_links T3mm ON T1.dbid = T3mm.parent_dbid  and 16804095 ="+
                             " T3mm.parent_fielddef_id  ) LEFT OUTER JOIN CQ_ADMIN.feature_1 T3 ON T3mm.child_dbid = T3.dbid  ) LEFT OUTER"+
                             " JOIN CQ_ADMIN.parent_child_links T4mm ON T3.dbid = T4mm.parent_dbid  and 16804263 = T4mm.parent_fielddef_id  )"+
                             " LEFT OUTER JOIN CQ_ADMIN.stakeholder T4 ON T4mm.child_dbid = T4.dbid  ) where T1.dbid <> 0 and ((T6.abbreviation ="+
                             " 'Test ES Eng Software' and T1.systemstate = 'Active')) and  ((T7.dbid in (select parent_dbid from"+
                             " CQ_ADMIN.parent_child_links where parent_fielddef_id = 16778767 and child_dbid in (select child_dbid from"+
                             " CQ_ADMIN.parent_child_links where parent_fielddef_id = 16777328 and parent_dbid = 33664106) ))) order by T3.name"+
                             " ASC,T1.systemname ASC";

            System.Data.DataSet ds = con.ExecuteDataset(CommandType.Text, sqltest);

            foreach (DataRow drCQ in ds.Tables[0].Rows)
            {

               string parent_system = drCQ["ParentSystem"].ToString();

               string support_system = drCQ["systemname"].ToString();
               //Response.Write(drCQ["systemname"] + " <B><I>Its parent is</I></B> " + drCQ["ParentSystem"] + "<BR />");
            }
        }

    I am wondering if it were possible to pull the the results into JavaScript so that I can make an array out of the results.  If so how would you do that?

    Thanks,

    Xana

    If history is to change let it change. If the world is to be destroyed so be it. If it is my fate to die ... I must simply laugh.
    Filed under: , , ,
  • Re: Pulling results from CodeBehind file into JavaScript

    07-17-2007, 11:36 AM

    just out of curiosity, why do you want to put the results into java script to make an array when you can just make a c# array?

    Please remember to click "Mark as Answer" on this post if it helped you.
  • Re: Pulling results from CodeBehind file into JavaScript

    07-17-2007, 11:44 AM
    • Loading...
    • XanaLyoko
    • Joined on 07-03-2007, 12:07 PM
    • Posts 68

    I want to create dynamically generated drop down menus without using a post back, and the only way that I could find to do it was to use javascript.

    If history is to change let it change. If the world is to be destroyed so be it. If it is my fate to die ... I must simply laugh.
  • Re: Pulling results from CodeBehind file into JavaScript

    07-17-2007, 12:02 PM

    well say you wanted to pass that to your javascript when the user clicks a button, you can try something like this  

    string myString = "this isnt the same as your text but hopefully you will get the idea";
    
    myButton.Attributes["onClick"] = "stringWork(myString);";
    
    //the stringWork is the java function to call when you click the button
    //the syntax might not be right for adding myString as the parameter
    //you might have to do something like "stringWork(\"" + myString + "\");";
    
    then in java something like this 
    function stringWork(myString)
    {
        //Now you can use java functions to break up your string how ever you want
    }
     
    Please remember to click "Mark as Answer" on this post if it helped you.
  • Re: Pulling results from CodeBehind file into JavaScript

    07-17-2007, 12:36 PM
    • Loading...
    • XanaLyoko
    • Joined on 07-03-2007, 12:07 PM
    • Posts 68

    All that the above seems to do is refresh my page.  I set into the javascript an alet to display the string but the alert does not fire.

    If history is to change let it change. If the world is to be destroyed so be it. If it is my fate to die ... I must simply laugh.
  • Re: Pulling results from CodeBehind file into JavaScript

    07-17-2007, 1:08 PM
    • Loading...
    • jjwhite
    • Joined on 03-08-2007, 8:09 PM
    • Philadelphia, PA
    • Posts 55

     You may have to add the attribute for "onclick" to the button control since it is not a server-side onclick event but a client side event.

    Button1.Attributes.add("onclick","javascriptfunction(parameters)")

     

    Jon White
    My Site
  • Re: Pulling results from CodeBehind file into JavaScript

    07-17-2007, 1:15 PM

    You may want to consider using AJAX. It fully supports dynamically generating dropdown lists without posting back the entire page.

  • Re: Pulling results from CodeBehind file into JavaScript

    07-17-2007, 1:26 PM
    • Loading...
    • XanaLyoko
    • Joined on 07-03-2007, 12:07 PM
    • Posts 68

    Dotnetjunkie, could you give an example of how to do this using AJAX? 

    I have not coded ajax at all.  I was trying to stick to JavaScript since I know it but if AJAX supports it I can try.

    If history is to change let it change. If the world is to be destroyed so be it. If it is my fate to die ... I must simply laugh.
Page 1 of 1 (8 items)
Microsoft Communities
Page view counter