Sign In  |  Register
 
 DotNetNuke Powered!
DotNetNuke Support Forums

DNN 4.5.3 ClientAPI Question

Rate this topic:

Please Register to post a reply.
Another benefit of registration is the ability to subscribe to and recieve notifications of new posts.

AuthorMessages
tigris7
Posts:18



03/03/2008 4:50 PM  

I am attempting to pass the selected value from a dropdownlist to a client side function but my code throws a 'Object reference not set to an instance of an object' exception when I try to register the client side variable. Please take a look and see if you can help.

In the .ascx file I have

<scripttype="text/javascript"src="/js/des.js">script> 

<asp:DropDownListID="DDL_Report_List"runat="server"AutoPostBack="True"OnSelectedIndexChanged="DDL_Report_List_SelectedIndexChanged" />

In the ascx.cs file in the page load I have:

 private string strURL;        //global var

 protectedvoid Page_Load(object sender, EventArgs e){protectedvoid DDL_Report_List_SelectedIndexChanged(object sender, EventArgs e)  

{

  if (!IsPostBack)    

   {ReportingService2005 rs = InstantiateRS();  

     Get_Report_List(rs);

     Bind_DDL_Report_List(DDL_Report_List); }

     else  {

        if (DDL_Report_List.SelectedIndex != 0) { 

        strURL = DDL_Report_List.SelectedValue;

        if(ClientAPI.BrowserSupportsFunctionality(ClientAPI.ClientFunctionality.DHTML))

           ClientAPI.RegisterClientReference(this.Page, ClientAPI.ClientNamespaceReferences.dnn); 

          try     {ClientAPI.RegisterClientVariable(this.Page, "rURL", strURL, true);}   //THIS IS THE LINE THAT THROWS THE EXCEPTION

          catch (Exception ex){ string temp = ex.ToString();}

    DDL_Report_List.SelectedIndex = 0;

  }

}

 

And then 

protected void DDL_Report_List_SelectedIndexChanged(object sender, EventArgs e){

string getReport = DDL_Report_List.SelectedValue; 

if(DDL_Report_List.SelectedIndex==2) //set global variable

strURL = @"http://10.0.3.40/Reports/Pages/Report.aspx?ItemPath=/BrokerReports/" + getReport;}

else //set global variable

strURL = @"http://10.0.3.40/Reports/Pages/Report.aspx?ItemPath=/BrokerReports/" + getReport + "?ReportID=CPC1&Firm=E&&rc:parameters=False&rc:Toolbar=false"

}

 In the js file I have:

Function GetRpt()

{

var url = dnn.getVar('rURL');

 

window.open(url, "one", "left=10, top=10, width=600, height=800, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no");

}

I have read the ClientAPI help doc and thik I may have to use ClientAPI.RegisterPostBackEvent, but can't quite grasp everything I am to do. Any help would be greatly appreciated. I know I still have to figure ut how to call GetRpt in the js file. Thanks in advance

John Mitchell
Posts:3196



03/04/2008 7:47 AM  
I personally do not use the ClientAPI. It is too bloated IMO and you can do those things much easier in a straight forward manner instead of wading through all that abstraction.

One easy way that might make your hard core code friends laugh, but will have you getting the job done with minimum effort is to put that small javascript function directly in the page and then set your variable with server-side tags something like this:

var url = '< %= rUrl %>';

//extra space added for the < % to make it show here.
John Mitchell
Posts:3196



03/04/2008 7:51 AM  

Rick Strahl takes this concept further in this article:

www.west-wind.com/weblog/posts/252178.aspx

tigris7
Posts:18



03/04/2008 11:31 AM  

Thanks, I'll take a look and consider your suggestion. I agree, it is a pain to use the ClientAPI, but initiallly I attempted coding and using client script the conventional way and did not have success. I'll revisit the issue.

Please Register to post a reply.
Another benefit of registration is the ability to subscribe to and recieve notifications of new posts.

Forums >DotNetNuke Support >General-DNN-Help > DNN 4.5.3 ClientAPI Question



ActiveForums 3.7
Visit our Store for great DotNetNuke Modules and Skins
DNNMasters Sitemap/Google Sitemap 3.0

Item codeSM3-01
Price$29.00
Product Information 
DotNetNuke CSS NavMenu 3.3 (Developers)

Item codeCSSNM33DEV
Base Price$149.00
Product Information 
Snapsis PageBlaster 3.3.2 for DotNetNuke - Professional Edition

AuthorJohn Mitchell
Base Price$79.00
Product Information 
XDAkuna (Web 2.0 CSS XHTML Skin)

Item codeXDAkuna
AuthorNina Meiers
Price$49.00
Product Information