Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 7th, 2007, 06:36 AM
Authorized User
 
Join Date: Dec 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with Ajax

Hello,
I have a drop down list box, which shows all pulishers from publisher table (pubs database). If we select any publisher from that list it will display the details of that publisher in a details view. I have tried it with ajax. But it is now working. It is not showing any error. Here is my code:
default.aspx
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
       <asp:DropDownList ID="ddlbox" runat="server" OnSelectedIndexChanged="SelectedIndexChanged"></asp:DropDownList>
        <asp:UpdatePanel ID="uPanel" runat="server">
            <ContentTemplate>
                <asp:DetailsView ID="dv" runat="server" AutoGenerateRows="false">
                <Fields>
                    <asp:BoundField HeaderText="ID" DataField="pub_id" />
                    <asp:BoundField HeaderText="Name" DataField="pub_name" />
                    <asp:BoundField HeaderText="City" DataField="city" />
                    <asp:BoundField HeaderText="State" DataField="state" />
                    <asp:BoundField HeaderText="Country" DataField="country" />
                </Fields>
                </asp:DetailsView>
                <asp:Label ID="label2" runat="server"></asp:Label>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ddlbox" EventName="SelectedIndexChanged" />
            </Triggers>
        </asp:UpdatePanel>
            &nbsp;
        </div>
    </form>
</body>

default.aspx.cs
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string source = WebConfigurationManager.ConnectionStrings["dbString"].ConnectionString;
            string sql = "SELECT pub_id, pub_name FROM publishers";
            SqlConnection con = new SqlConnection(source);
            con.Open();
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            DataSet ds = new DataSet();
            da.Fill(ds, "pubss");
            con.Close();
            ddlbox.DataSource = ds;
            ddlbox.DataTextField = "pub_name";
            ddlbox.DataValueField = "pub_id";
            ddlbox.DataBind();
        }

    }

    protected void SelectedIndexChanged(object sender, EventArgs e)
    {
        string id = ddlbox.SelectedValue;
        label2.Text = id;
        string source1 = WebConfigurationManager.ConnectionStrings["dbString"].ConnectionString;
        string sql1 = "SELECT * FROM publishers WHERE pub_id='" + id + "'";
        SqlConnection con1 = new SqlConnection(source1);
        con1.Open();
        SqlCommand cmd1 = new SqlCommand(sql1, con1);
        SqlDataAdapter da1 = new SqlDataAdapter();
        da1.SelectCommand = cmd1;
        DataSet ds1 = new DataSet();
        da1.Fill(ds1, "pubs");
        con1.Close();
        dv.DataSource = ds1;
        dv.DataBind();
    }
}

Please help me. I cannot understand where is the problem.
Angshujit

__________________
Angshujit
 
Old February 7th, 2007, 09:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there...

move the combo box inside the update panel and try again...
also try this..
forget about your code and use directly an SqlDataSource that receive a parameter from the combo, that way you forget about all the code you write and also you can throw away the trigger for the update panel...



HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
 
Old February 8th, 2007, 03:03 AM
Authorized User
 
Join Date: Dec 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,
thanks for your reply. I have used your first option. Now it is workin.
Now I have tried a little bit more with ajax, and again I have faced a problem.
I have inserted a tree view control in a master page. code is here:

<asp:TreeView ID="tv" runat="server" DataSourceID="xmlds" ShowLines="True">
   <DataBindings>
      <asp:TreeNodeBinding DataMember="rootNode" Text="Tree" Value="Tree" />
      <asp:TreeNodeBinding DataMember="siteNode" TextField="title" />
   </DataBindings>
</asp:TreeView>
<asp:XmlDataSource ID="xmlds" runat="server" DataFile="viewtree.xml"></asp:XmlDataSource>

What i want is that, when any one click on any node of the tree, it will show some information in the content page (with ajax). But I cannot understand how to do this. Please help me.

 
Old February 8th, 2007, 08:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

as far as I know, you will have to put an update panel that cover that tree and the content page..

the simple rule is this, when you want to update something from another thing, the two of them have to be in the same update panel...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
 
Old February 8th, 2007, 05:16 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
quote:as far as I know, you will have to put an update panel that cover that tree and the content page..
Is that true? Can't you set up Triggers to make the UpdatePanel refresh based on controls outside the panel?

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old February 9th, 2007, 02:50 AM
Authorized User
 
Join Date: Dec 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank all of you. It is working. I have done it with the help of trigger. Now I want do discuss one thing more.
My tree nodes are actually stored in a database table. I have created the viewtree.xml file from that database. The xml file is created only one time. My tree may contains more than one thousand nodes. All the tasks except add node and delete node are processed with the help of ajax. So it is working very fast. But in the case of node add and node delete I need to add the node in the database and the tree is re-created. And it is taking a lot of time. Is there any process to minimize the time to load the page?
Another thing is that, nodes may have same name. When any one click on any node I need the id of that node to search the database. How can I set an id to each node(In my database every node has an unique id).
Thank you.
Angshujit
 
Old February 12th, 2007, 03:13 AM
Authorized User
 
Join Date: Dec 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello all,
I am really facing a problem to detect which node is selected. Because more than one node may have same name. Please help me. It is urgent.

Angshujit

 
Old February 12th, 2007, 08:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. why can't you just use the same id of the DB into the tree???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
 
Old February 12th, 2007, 09:37 AM
Authorized User
 
Join Date: Dec 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello,
At present I am creating the viewtree.xml file by using SQLXML. It is creating the xml file. The file looks like....
<?xml version='1.0' encoding='utf-8' ?>
<rootNode>
  <siteNode title="root" id="1">
    <siteNode title="my document" id="3">
      <siteNode title="my films" id="31">
        <siteNode title="bengalis" id="33">
          <siteNode title="aaa102" id="102" />
          <siteNode title="aaa106" id="106">
            <siteNode title="xxxx1" id="1051" />
            <siteNode title="xxxx1" id="1053" />
            <siteNode title="zzzz2" id="1059" />
                          ....
                          ....
From this file I am creating the tree view. Could you please explain how I can use this id?
Angshujit

 
Old February 15th, 2007, 08:46 PM
Authorized User
 
Join Date: Apr 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Default

http://ajax.asp.net/docs/overview/Up...aspx#Scenarios

According here, Treeview is not supperted for UpdatePanel. Issues I assume as i knew they have an example with it when it was called Atlas. Anyway, you do not need the control inside the update panel to trigger that update panel. If you have a button and want to use it to refresh a panel, just use the click even of that control as the trigger. Only put what you want re-rendered in the updatepanel. Putting stuff that doesn't need to be re-rendered creates some overhead I believe as that control's info is sent back to the server as well. You only want to send back what is needed to be sent back and retrieved for performance.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with AJAX in Firefox geoko BOOK: Professional Ajax ISBN: 978-0-471-77778-6 2 June 27th, 2009 11:57 AM
Ajax Problem kalyanykk ASP.NET 3.5 Basics 3 November 14th, 2008 08:33 PM
Problem with ajax updatepanel alexmalayil ASP.NET 2.0 Professional 0 October 18th, 2007 05:07 AM
problem with ajax amit1me BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 September 28th, 2007 01:14 AM
problem with ajax amit1me Ajax 2 January 16th, 2007 02:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.