?
Solved

Lack of understanding with AsyncPostback concept and no success with Variables in T-SQL for SqlDataSource  ASP.net in C

Posted on 2014-11-13
5
Medium Priority
?
129 Views
Last Modified: 2014-11-17
I'm working on an interactive map that combines Asp.net in C and the Google Maps Api v3.
 Here is my code....

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%--<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>--%>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">

<style type="text/css">
     
  #map_canvas  
  {
    width:570px; 
    height:596px;
    border: 2px solid #660000;
  }
   
   
   #msgResult 
   {
     color:Red;
     font-weight:bold;
     height: 25px;
   }
   
</style>


<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="Scripts/googleMap.js"></script>

<script type="text/javascript">

    function fillBorderTwnRngLstBox(tr, trid) {

        var trLstBx = document.getElementById("MainContent_lstbxBorderingTwnRng");
        var el = document.createElement("option");
        el.textContent = tr;
        el.value = trid;
        trLstBx.appendChild(el);
    }


    function clearBorderTwnRngLstBox() {

        var trLstBx = document.getElementById("MainContent_lstbxBorderingTwnRng");
        trLstBx.innerHTML = "";
    }


    function displayResultMsg(msg) {

        msgSpan = document.getElementById("msgResult");
        msgSpan.innerHTML = msg;
    }


    function clearForm() {        

        cList = document.getElementById("MainContent_CountyList");
        cList.value = 0;
        triggerEvent(cList, 'onchange');

        tList = document.getElementById("MainContent_TwnList");
        tList.value = 0;
        triggerEvent(tList, 'onchange');

        rList = document.getElementById("MainContent_RngList");
        rList.value = 0;
        triggerEvent(rList, 'onchange');

        sList = document.getElementById("MainContent_SectionList");
        sList.value = 0;
        triggerEvent(sList, 'onchange');

        displayResultMsg("");
    }


    function triggerEvent(el, type) {
        if ((el[type] || false) && typeof el[type] == 'function') {
            el[type](el);
        }
    }


</script>

</asp:Content>




<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

    <asp:ScriptManager ID="ScriptManager1" runat="server">
             </asp:ScriptManager>

   <%--<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>--%>

    
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <Triggers>
             <asp:AsyncPostbackTrigger ControlID="CountyList" EventName="SelectedIndexChanged" />
             <asp:AsyncPostbackTrigger ControlID="TwnList" EventName="SelectedIndexChanged" />
             <asp:AsyncPostbackTrigger ControlID="RngList" EventName="SelectedIndexChanged" />
             <asp:AsyncPostbackTrigger ControlID="SectionList" EventName="SelectedIndexChanged" />
             <asp:AsyncPostbackTrigger ControlID="btnReset" EventName="Click" />
        </Triggers>        
    </asp:UpdatePanel>
    
    <table>
    <tr>            
    <td>
        County:
        <asp:DropDownList ID="CountyList" runat="server" DataSourceID="CountyDataSource" 
                DataTextField="CountyName" DataValueField="FIPSID"  
                AppendDataBoundItems="True" EnableViewState="True" AutoPostBack="True"
                OnSelectedIndexChanged="CTRSList_SelectedIndexChanged">
                <asp:ListItem Value="0" Text=""></asp:ListItem>
        </asp:DropDownList>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </td>

    <td>
        Township:
        <asp:DropDownList ID="TwnList" runat="server" DataSourceID="TwnDataSource" 
                DataTextField="TWN" DataValueField="TOWNSHIPID" 
                AppendDataBoundItems="True" EnableViewState="True" AutoPostBack="True"
                OnSelectedIndexChanged="CTRSList_SelectedIndexChanged">
                <asp:ListItem Value="0" Text=""></asp:ListItem>
        </asp:DropDownList>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </td>

    <td>
        Range:
        <asp:DropDownList ID="RngList" runat="server" DataSourceID="RngDataSource" 
                DataTextField="RNG" DataValueField="RANGEID" 
                AppendDataBoundItems="True" EnableViewState="True" AutoPostBack="True"
                OnSelectedIndexChanged="CTRSList_SelectedIndexChanged">
                <asp:ListItem Value="0" Text=""></asp:ListItem>
        </asp:DropDownList>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;         
    </td>

    <td>
        Section:
        <asp:DropDownList ID="SectionList" runat="server" DataSourceID="SecDataSource" 
                DataTextField="SECTION" DataValueField="SECID" 
                AppendDataBoundItems="True" EnableViewState="True" AutoPostBack="True"
                OnSelectedIndexChanged="CTRSList_SelectedIndexChanged">
                <asp:ListItem Value="0" Text=""></asp:ListItem>
        </asp:DropDownList>
                
    </td>
    </tr>

    <tr>
    <td colspan="2" align="left">
        
        <div id="msgResult"></div>
        
    </td>
    <td colspan="2" align="right">
        
        <asp:Button ID="btnReset" runat="server" OnClick="btnReset_Click" Text="Reset" />
        
    </td>
    </tr>    
    </table>



    <table>
    <tr>
    <td>
        <div id="map_canvas">        
        </div>
    </td>
    <td>
        <asp:ListBox ID="lstbxBorderingTwnRng" runat="server"  
             Width="100px" AutoPostBack="True"></asp:ListBox>
    </td>
    </tr>
    </table>
    



    <asp:SqlDataSource ID="CountyDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT FIPSID, CountyName
                        FROM tblCounty
                        WHERE FIPSID NOT IN (998,9999)
                        ">
    </asp:SqlDataSource>


    <asp:SqlDataSource ID="TwnDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT TOWNSHIPID, TWN
                        FROM tblTownship
                        WHERE TOWNSHIPID NOT IN (44,45,46,47,48,57,58,115,116)
                        ORDER BY TWN
                        ">
    </asp:SqlDataSource>


    <asp:SqlDataSource ID="RngDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT RANGEID, RNG
                        FROM tblRange
                        WHERE RANGEID NOT IN (49,50,51,52,53,54,55,56,57)
                        ORDER BY RNG
                        ">
    </asp:SqlDataSource>


    <asp:SqlDataSource ID="SecDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT SECID, SECTION FROM tblSection WHERE SECID <= 36">
    </asp:SqlDataSource>


    <asp:SqlDataSource ID="dsGetCTR" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT ID, f_TR_id  FROM [tblBoundary] 
                        WHERE ([f_county_id] = @ctyID)
                        AND ([f_TR_id] = (SELECT TRID from tblTR WHERE T_ID = @twnID AND R_ID = @rngID))
                        AND ([f_sec] = 173)
                        AND ([f_quad_id] = 9999)
                        ">
        <SelectParameters>            
            <asp:Parameter Name="ctyID" />
            <asp:Parameter Name="twnID" />
            <asp:Parameter Name="rngID" />
        </SelectParameters>
    </asp:SqlDataSource>


    <asp:SqlDataSource ID="dsGetCTRS" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT ID, f_TR_id  FROM [tblBoundary] 
                        WHERE ([f_county_id] = @ctyID)
                        AND ([f_TR_id] = (SELECT TRID from tblTR WHERE T_ID = @twnID AND R_ID = @rngID))
                        AND ([f_sec] = @secID)
                        AND ([f_quad_id] = 9999)
                        ">
        <SelectParameters>            
            <asp:Parameter Name="ctyID" />
            <asp:Parameter Name="twnID" />
            <asp:Parameter Name="rngID" />
            <asp:Parameter Name="secID" />
        </SelectParameters>
    </asp:SqlDataSource>


    <asp:SqlDataSource ID="dsGetTR" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT ID, f_TR_id  FROM [tblBoundary] 
                        WHERE ([f_county_id] = 9999)
                        AND ([f_TR_id] = (SELECT TRID from tblTR WHERE T_ID = @twnID AND R_ID = @rngID))
                        AND ([f_sec] = 173)
                        AND ([f_quad_id] = 9999)
                        ">
        <SelectParameters>
            <asp:Parameter Name="twnID" />
            <asp:Parameter Name="rngID" />
        </SelectParameters>
    </asp:SqlDataSource>


    <asp:SqlDataSource ID="dsGetTRS" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT ID, f_TR_id  FROM [tblBoundary] 
                        WHERE ([f_county_id] = 9999)
                        AND ([f_TR_id] = (SELECT TRID from tblTR WHERE T_ID = @twnID AND R_ID = @rngID))
                        AND ([f_sec] = @secID)
                        AND ([f_quad_id] = 9999)
                        ">
        <SelectParameters>
            <asp:Parameter Name="twnID" />
            <asp:Parameter Name="rngID" />
            <asp:Parameter Name="secID" />
        </SelectParameters>
    </asp:SqlDataSource>


    <asp:SqlDataSource ID="dsGetCty" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT ID  FROM [tblBoundary] 
                        WHERE ([f_county_id] = @ctyID)
                        AND ([f_TR_id] = 1576)
                        AND ([f_sec] = 173)
                        AND ([f_quad_id] = 9999)
                        ">
        <SelectParameters>            
            <asp:Parameter Name="ctyID" />
        </SelectParameters>
    </asp:SqlDataSource>


    <asp:SqlDataSource ID="dsGetBorderingTwnRngList" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="spGetBorderingTwnRng" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:Parameter Name="trID" />            
        </SelectParameters>
    </asp:SqlDataSource>


   </asp:Content>

Open in new window

   

Here is my code behind (which has been trimmed down)....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "Google Maps Initialization",
                      string.Format("initializeMap();"), true);
        }
        //else
        //{
        //    errorLabel.Text = "After postback";
        //}
    }


    

    protected void CTRSList_SelectedIndexChanged(object sender, EventArgs e)
    {        
        //errorLabel.Text = ""; //This doesn't work!!
        ScriptManager scriptManager = ScriptManager.GetCurrent(Page);
        var ctyID = CountyList.SelectedValue;
        var twnID = TwnList.SelectedValue;
        var rngID = RngList.SelectedValue;
        var secID = SectionList.SelectedValue;
        
       
         if (ctyID == "0" & twnID != "0" & rngID != "0" & secID == "0") // Township and Range
        {
            //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "TR",
            //         "displayResultMsg('TR');", true);
            
            dsGetTR.SelectParameters["twnID"].DefaultValue = twnID;
            dsGetTR.SelectParameters["rngID"].DefaultValue = rngID;

            DataView dvBnd = (DataView)dsGetTR.Select(DataSourceSelectArguments.Empty);
            DataTable dtBnd = dvBnd.ToTable();

            if (dtBnd.Rows.Count > 1)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Multiple BndIDs",
                     "displayResultMsg('Multiple BndIDs!');", true);

                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Clear Map",
                     "clearMap();", true);
            }
            else if (dtBnd.Rows.Count == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Location Does Not Exist",
                     "displayResultMsg('Location Does Not Exist!');", true);

                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Clear Map",
                     "clearMap();", true);
            }
            else
            {
                //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "CTR",
                //         "displayResultMsg(" + dtBnd.Rows[0][0].ToString() + ");", true);
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "",
                         "displayResultMsg('');", true);

                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Clear Section",
                         "clearSection();", true);

                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Clear County",
                         "clearCounty();", true);

                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Get Township Polygon",
                         "getTownship(" + twnID + ", " + rngID + ");", true);

                DataRowView row = (DataRowView)dvBnd[0];
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "CTR",
                         "displayResultMsg(" + row["f_TR_id"].ToString() + ");", true);
                dsGetBorderingTwnRngList.SelectParameters["trID"].DefaultValue = row["f_TR_id"].ToString();
                DataView dvBTrBnd = (DataView)dsGetBorderingTwnRngList.Select(DataSourceSelectArguments.Empty);
                DataTable dtBTrBnd = dvBTrBnd.ToTable();
                //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "CTR",
                //         "displayResultMsg(" + dtBTrBnd.Rows.Count.ToString() + ");", true); //dtBTrBnd.Rows[0][0].ToString()

                //lstbxBorderingTwnRng.Items.Clear();
                //lstbxBorderingTwnRng.Rows = dtBTrBnd.Rows.Count;

                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Clear List Box",
                         "clearBorderTwnRngLstBox();", true);

                foreach (DataRow trRow in dtBTrBnd.Rows)
                {
                    //lstbxBorderingTwnRng.Items.Add(trRow["TRID"].ToString());
                    //fillBorderTwnRngLstBox(tr, trid);
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "TR List Box",
                         "fillBorderTwnRngLstBox(" + trRow["TRID"].ToString() + ", " + trRow["TRID"].ToString() + ");", true);
                    //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Alert",
                         //"window.alert(" + trRow["TRID"].ToString() + ");", true); 
                }

                //lstbxBorderingTwnRng.DataSource = dtBTrBnd; //dtBTrBnd.DefaultView 
                //lstbxBorderingTwnRng.DataTextField = "TRID"; //twnRng,  dtBTrBnd.Columns["TRID"].ToString()
                //lstbxBorderingTwnRng.DataValueField = "TRID";
                               
                ////lstbxBorderingTwnRng.DataMember = "TRID";
                //lstbxBorderingTwnRng.DataBind();
            }
              
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "No Can Do",
                     "displayResultMsg('');", true);
        }
        
    }


    protected void btnReset_Click(object sender, System.EventArgs e)
    {        
        ScriptManager scriptManager = ScriptManager.GetCurrent(Page);
        //CountyList.ClearSelection(); //Doesn't work!
        //CountyList.SelectedIndex = -1; //Doesn't work!       
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Clear Form",
                     "clearForm();", true);

        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Clear Map",
                     "clearMap();", true);
    }  

}

Open in new window


Problem 1:
In order to get this to work correctly I have an UpdatePanel with AsyncPostbackTriggers, primarily for drop-down menus.   I'm finding this AsyncPostback concept to be a pain to deal with and don't really understand why it's needed.   I've had to resort  to using javascript to get some things to work, such as reset the drop-down menus, display messages, and fill a listbox.   I don't understand why this won't work...
CountyList.ClearSelection();
or this....
errorLabel.Text = "";
and especially this....
lstbxBorderingTwnRng.DataSource = dtBTrBnd;
lstbxBorderingTwnRng.DataTextField = "TRID";
lstbxBorderingTwnRng.DataValueField = "TRID";
lstbxBorderingTwnRng.DataBind();
Why must I resort to javascript?

Problem 2:
For this map I'd like to not only show the selected Township and Range on the map, but I'd also like to show the township polygons that border the selected one.  As mentioned in problem 1, I've had to use javascript to do this.   But there appears to be a problem with either using a declared variable or concatenating columns and using 'AS' with a sqldatasource but I'm not sure which it is.   Here is my stored procedure...
ALTER PROCEDURE [dbo].[spGetBorderingTwnRng] 
	-- Add the parameters for the stored procedure here
	@trID As int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	DECLARE @tr As Geometry
    SET @tr = (SELECT TR_geom FROM tblTR WHERE TRID = @trID)

    SELECT TRID, TWN + ' ' + RNG AS twnRng FROM tblTR 
    INNER JOIN tblTownship ON tblTR.T_ID = tblTownship.TOWNSHIPID 
    INNER JOIN tblRange ON tblTR.R_ID = tblRange.RANGEID
    WHERE TR_geom.STTouches(@tr) = 1
END

Open in new window

I should return about 7 townships and using this, dtBTrBnd.Rows.Count, confirms that, but my listbox will only show 1 value.  Can anyone assist me please?
0
Comment
Question by:Nate_LR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:Kelvin McDaniel
ID: 40442917
It's been a while since I've dealt with WebForms... but If I remember correctly:

1, anything that has runat="server" is pre-processed and sent to the client as HTML... this is true if it is the result of an ajax postback or not.

2. All postbacks are full page postbacks... the UpdatePanels fake it by only updating the part covered by the trigger which sent the postback.

3. Unless you're re-rendering the ENTIRE block within the targeted UpdatePanel you're not going to see the behavior you're expecting.

Basically my gut reaction is that WebForms isn't the optimal project type for what you're trying to do on this particular page. What you're trying to do is not impossible, but it will be more difficult than it conceptually should be. This probably ought to be an MVC page/view. WebForms were meant to make the transition for WinForms developers to the web easier.

If I'm envisioning this correctly you're running into page lifecycle (timing) and JavaScript collision issues. If at all possible you should seriously consider removing the ASP.NET Ajax pieces so that you can get the initial view to render as expected. After that just use regular JavaScript to interact with the Google Maps api. I recommend using either a .asmx or WebApi service to provide the data you want to use with the Google Maps api. That will give you the ease of developing as well as still allow you to provide a rich experience for your users.
0
 

Author Comment

by:Nate_LR
ID: 40443768
Thanks for the response.    I made a test form for filling a listbox.  This works as expected.....
protected void Page_Load(object sender, EventArgs e)
    {        
        dsGetBorderingTwnRngList.SelectParameters["trID"].DefaultValue = "82";
        DataView dvBTrBnd = (DataView)dsGetBorderingTwnRngList.Select(DataSourceSelectArguments.Empty);
        DataTable dtBTrBnd = dvBTrBnd.ToTable();

        lstbxBorderingTwnRng.DataSource = dtBTrBnd; //dtBTrBnd.DefaultView 
        lstbxBorderingTwnRng.DataTextField = "TRID"; //twnRng,  dtBTrBnd.Columns["TRID"].ToString()
        lstbxBorderingTwnRng.DataValueField = "TRID";           
        lstbxBorderingTwnRng.DataBind();           
    }

Open in new window


7 values are displayed in the listbox.  So using a declared variable or concatenating columns and using 'AS' with a sqldatasource is not the issue.   When I try to fill the listbox with javascript it only displays 1 value so it seems like it's not going through the foreach loop or it's not appending to the listbox....
protected void btnTest_Click(object sender, EventArgs e)
    {
        ScriptManager scriptManager = ScriptManager.GetCurrent(Page);

        dsGetBorderingTwnRngList.SelectParameters["trID"].DefaultValue = "82";
        DataView dvBTrBnd = (DataView)dsGetBorderingTwnRngList.Select(DataSourceSelectArguments.Empty);
        DataTable dtBTrBnd = dvBTrBnd.ToTable();

        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Clear List Box",
                 "clearBorderTwnRngLstBox();", true);
        
        foreach (DataRow trRow in dtBTrBnd.Rows)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "TR List Box",
                 "fillBorderTwnRngLstBox('" + trRow["twnRng"].ToString() + "', " + trRow["TRID"].ToString() + ");", true);
        }
}

Open in new window


So I tried passing the datatable rows into fillBorderTwnRngLstBox2 which has an array as an argument....
function fillBorderTwnRngLstBox2(trList) {

        var trLstBx = document.getElementById("MainContent_lstbxBorderingTwnRng");

        for (i = 0; i < trList.length; i++) {
            var el = document.createElement("option");
            el.text = trList[i];
            el.value = trList[i];
            //trLstBx.appendChild(el);
            trLstBx.add(el, null);
        }               
    }

Open in new window

which didn't work.  Then I tried converting the datatable to a list and then back into an array.....
protected void btnTest_Click(object sender, EventArgs e)
    {
        ScriptManager scriptManager = ScriptManager.GetCurrent(Page);

        dsGetBorderingTwnRngList.SelectParameters["trID"].DefaultValue = "82";
        DataView dvBTrBnd = (DataView)dsGetBorderingTwnRngList.Select(DataSourceSelectArguments.Empty);
        DataTable dtBTrBnd = dvBTrBnd.ToTable();

        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Clear List Box",
                 "clearBorderTwnRngLstBox();", true);

        List<int> twnList = new List<int>();
        foreach (DataRow trRow in dtBTrBnd.Rows)
        {
            //twnList.Add(trRow["twnRng"].ToString());
            twnList.Add(int.Parse(trRow["TRID"].ToString()));
        }

        int[] twnNames = twnList.ToArray();

        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "TR List Box",
                 "fillBorderTwnRngLstBox2(" + twnNames + ");", true);        
    }

Open in new window

but this will only work if I do this.. fillBorderTwnRngLstBox2('" + twnNames + "');", true) , but then it's a string argument.  The listbox will fill with...
S
y
s
t
e
m
.
I
n
t
3
2
[
]
What am I doing wrong?
0
 
LVL 11

Accepted Solution

by:
Kelvin McDaniel earned 2000 total points
ID: 40446218
In all seriousness, congratulations for figuring out that you *can* at least do what you're trying to do.

The reason why it's giving you that object type name is because that's what you're telling it to do at line #19 above; since it doesn't have a string value it's giving you back the default string value of it -- the object type name.

I also think you might be mismatching the intent of your JavaScript method in the codebehind... sometimes getting JavaScript to "obey" can be difficult if you're not as explicit as possible.

In the spirit of being explicit, let's try this for lines 12 through 22 above in your codebehind:
System.Text.StringBuilder twnNames = new System.Text.StringBuilder();
foreach (DataRow trRow in dtBTrBnd.Rows)
{
	// we actually don't need to turn these IDs into ints because they'll eventually end up being strings anyway
	twnNames.AppendFormat("{0},", trRow["TRID"]);
}

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "TR List Box",
                 "fillBorderTwnRngLstBox2(" + twnNames.ToString() + ");", true);

Open in new window


And the for the javascript, modify your function as below:
function fillBorderTwnRngLstBox2(trList) {
	var trLstBx = document.getElementById("MainContent_lstbxBorderingTwnRng");
	var incomingValues = trList.split(",");
	
	for (i = 0; i < incomingValues.length; i++) {
		var el = document.createElement("option");
		el.text = incomingValues[i];
		el.value = incomingValues[i];
		trLstBx.add(el, null);
	}               
}

Open in new window


Hopefully that should do it.
0
 

Author Comment

by:Nate_LR
ID: 40447580
Thank-you!  I modified it just a bit...
StringBuilder twnNames = new StringBuilder();
        twnNames.Append("var twnArray = [];");
        foreach (DataRow trRow in dtBTrBnd.Rows)
        {            
            twnNames.Append("twnArray.push(['" + trRow["twnRng"] + "', " + trRow["TRID"] + "]);");
        }

        twnNames.Append("fillBorderTwnRngLstBox2(twnArray); ");

        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "TR List Box",
                 twnNames.ToString(), true);

Open in new window


function fillBorderTwnRngLstBox2(trList) {

        var trLstBx = document.getElementById("MainContent_lstbxBorderingTwnRng");

        for (i = 0; i < trList.length; i++) {
            var el = document.createElement("option");
            el.text = trList[i][0];
            el.value = trList[i][1];
            trLstBx.appendChild(el);
        }  
    }

Open in new window

0
 

Author Closing Comment

by:Nate_LR
ID: 40447581
Thanks again!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question