Showing posts with label box. Show all posts
Showing posts with label box. Show all posts

Monday, March 26, 2012

Duplicate Items in dropdownlist inside an Updatepanel

Hi,

I have been working with Atlas for the past couple of weeks and I have a very simple page with a dropdownlist box inside a updatepanel. I have a button that inserts a value in the back-end database and refresh the dropdownlist. This button is also a trigger for the updatepanel. This dropdownlist is bounded to an ObjectDataSource.

The problem is that on the first click, the values in the dropdownlist are duplicated with the original list and plus the new value. So I have the original list show up twice and the new value at the end. However, on the second click, the dropdownlist is updated correctly with only the new value being appended at the end. Doesn't anyone have the same problem?

ThanksSmile

<atlas:UpdatePanelID="UpdatePanelReason"runat="server"Mode="Conditional">

<ContentTemplate>

<asp:DropDownListID="drpReason"runat="server"AppendDataBoundItems="True"DataSourceID="ObjectDataSource1"DataTextField="ITEM_SUB_TYPE_NAME"DataValueField="PK_ITEM_SUB_TYPE_ID">

<asp:ListItemValue="0">Select Reason</asp:ListItem>

</asp:DropDownList>

</ContentTemplate>

<Triggers>

<atlas:ControlEventTriggerControlID="btnAddReason"EventName="Click"/>

</Triggers>

</atlas:UpdatePanel>

My post-back method to insert a new value in the dropdownlist.

ProtectedSub btnAddReason_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles btnAddReason.Click

IfMe.txtNewReason.Text <>String.EmptyThen

Dim lookupMgrAsNew LookupManager

lookupMgr.insertItemSubType(Me.txtNewReason.Text, Session("ItemType"))

Me.drpReason.DataBind()

EndIf

EndSub

Problem solved!! All I have to do is clear all the items in the dropdownlist before calling databinding.

:)

Dummie question about UpdatePanel

I have a problem which can be sumarized in the following:

- UpdatePanel with a button

- Text box outside update panel

- Want button "click" method to update the text in the textbox.

How is this possible? I have read some suggestions (Luis Abreu suggests a "dummie button" with _DoPostBack. The problem is I am very new to asp so have no idea about where and how to place the code and have no idea about how javascript works in the page, so I did not underestand that solution nor how to implement it...

Any help is appreciated!

I've say you should put the things that you want updated inside the UpdatePanel, with a Trigger on the button click event. The button does not have to reside inside the UpdatePanel. So, your example should be reversed, with the UpdatePanel with a textbox and a button outside the UpdatePanel.
Hi,

quick example that illustrates what senyl said above:

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void btnUpdate_Click(object sender, EventArgs e) { txtDate.Text = DateTime.Now.ToString(); }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <atlas:ScriptManager ID="scriptManager" runat="server" EnablePartialRendering="true"></atlas:ScriptManager> <atlas:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <atlas:ControlEventTrigger ControlID="btnUpdate" EventName="Click" /> </Triggers> <ContentTemplate> <asp:TextBox ID="txtDate" runat="server"></asp:TextBox> </ContentTemplate> </atlas:UpdatePanel> <asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click" /> </form></body></html>

senyl:

I've say you should put the things that you want updated inside the UpdatePanel, with a Trigger on the button click event.  The button does not have to reside inside the UpdatePanel.  So, your example should be reversed, with the UpdatePanel with a textbox and a button outside the UpdatePanel.

The problem is that my real scenario is slightly more complicated:

One of the UpdatePanels is a GridView with a column which is a button for "add new row". As it is embedded in the gridview, I can't take it out.

The other updatePanel is a FormView that becomes visible when the former button is clicked. It then shows insert boxes and it has a "insert" button that also needs to be in the formview...to insert the record.

Well, my best advice is to watch that video by Scott Gutherie on the Atlas homepage, where he uses a gridview and a formview with atlas. You could also make the updatepanels render always, and code the triggers properly.

Hope this helps (it probably won't, but it is my best guess)

Saturday, March 24, 2012

dropdownlist inside a update panel is not updating

Hello,
I have a update panel and inside that panel I have three items, dropdownlist, text box and button.
Dropdownlist is being bound to select statement (SqlDatasource) which retrieve list of boxes borrow by department.
Text box is used to updated the information for person name who returned the box.
Button is used when I want to update the information for a retunbox.in the button event handler I update the status of box from borrow to return with the name of the return person and display the information result to end user for success of failure.

I can see the sauces information on the gui and also see the in the database it is updating.
When I refresh the page it remove that box number from the dropdownlist but not when I click the button to update the information. I have set the trigger for updatepanel to conditional mode with button click.

I also try to programatically updated the dropdownlist (both when first time it load the page and on clicking the button) but it still didn't work.

Any help would be really appreciated.

Thanks

F5 refresh doesnot support in Ajax and there is no need for the trigger as the button is already inside the update panel since all child controls are trigger by default

rohit


Thanks.

But the problem still remains same, dropdownlist is not updated once the button is clicked and it has changed the status from borrowed to retuned in the database. Dropdownlist still show the box number as borrowed box.


I assume your button click calls a function.

In that case try to call the update function of the updatepanel.

e.g. <asp:UpdatePanel ID="MyUpdatePanel" .........

Button Click Function:

MyUpdatePanel.Update();

If it's not working, post your HTML here so others can help.

Aeires.


No, this doesn't work.

Here is the code:

<asp:UpdatePanel ID="updatePanelBorrow" runat="server">
<contenttemplate>

<asp:Panel id = "plborrrow" runat="server">

<asp:DropDownList onblur="ResetColor()" id="ddlQABoxList" onfocus="ChangeColor()" tabIndex=3 runat="server" Width="154px" ToolTip="Select SafeGuard No to Borrow it" AppendDataBoundItems="True" CausesValidation="True"><asp:ListItem Value="-1">Choose a SafeGuard</asp:ListItem></asp:DropDownList>

<asp:Textbox id="txtname" runat="server"/>

<asp:Button id="btnSaveBorrow" tabIndex=8 onclick="btnSaveBorrow_Click" runat="server" Text="Save Borrow Info" Width="111px" SkinID="TopPanelSkinID" ToolTip="Update Borrow information for the Safeguard box or QA Box"></asp:Button

</asp:Panel>
</contenttemplate>

</asp:UpdatePanel>

Here is code : first to bind dropdownlist (it is basically box numbers)

public void GetQABoxList()
{
_connection = new SqlConnection(_connString);
//The command object for sql statement
_command = new SqlCommand();
try
{
_connection.Open();
_command.Connection = _connection;
_command.CommandText = "spListOfQABoxes";
_command.CommandType = CommandType.StoredProcedure;

//Execute the insert statemtent

dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand = _command;
dataAdapter.TableMappings.Add("Table", "[QA Box]");

DataSet dataset = new DataSet();
dataAdapter.Fill(dataset);

ddlQABoxList.DataSource = dataset.Tables["[QA Box]"].DefaultView;
ddlQABoxList.DataTextField = "boxNo";
ddlQABoxList.DataValueField = "boxNo";
ddlQABoxList.DataBind();

}
catch (Exception exp)
{
Trace.Write(exp.Message);
}
finally
{
_command.Dispose();
_connection.Close();
}
}

Code for button click:

protected void btnSaveBorrow_Click(object sender, EventArgs e)
{
lblMessage.Visible = false;
lblMessage.Text = "";
String boxno = ddlQABoxList.SelectedItem.Text;


_connection = new SqlConnection(_connString);

//The command object for sql statement
_command = new SqlCommand();
try
{
_connection.Open();
_transaction = _connection.BeginTransaction();
_command.Transaction = _transaction;
_command.Connection = _connection;

_command.CommandType = CommandType.StoredProcedure;
_command.CommandText = "spUpdateBorrowBoxInfo";

//Execute the insert statemtent
int val = _command.ExecuteNonQuery();
if (val > 0)
{
plReturn.Visible = false;
lblMessage.Visible = true;
lblMessage.Text = "Borrow information for QA Box # " + boxno + " has been Updated";

// ddlQABoxList.DataSource = dsBorrowBox;
// ddlQABoxList.DataBind();

txtBorrowedName.Text = "";
txtContents.Text = "";
}
_transaction.Commit();
// GetQABoxList();
DataBindDept();
}
catch (Exception exp)
{
lblMessage.Visible = true;
lblMessage.Text = exp.Message.ToString();
Page.SetFocus(ddlQABoxList);
Trace.Write(exp.Message);
}
finally
{
_command.Dispose();
_connection.Close();
}
// GetQABoxList(); use these two lines to enforce to update dropdownlist, NO SUCCESS!
// UpdatePanelAndDDL();
}

it looks like your problem is the dropdown is not refreshing after button click event, for that u need to call GetQABoxList() againg to refresh your dropdown list.

if this is not what you want then please explain your problem more clearly.

Rohit


Well, In the button_Click eventhandler I do call the GetQABoxList() as my primary concern is to get the latest list of qa boxes numbers to bind with dropdownlist. I commnet out this method but it was not working for me.

Thanks


try putting

ddlQABoxList.SelectedIndex = 0 at the end of GetQABoxList() and see if it works for you.


and one thing include

ddlQABoxList.Clear() in the the begining and

ddlQABoxList.SelectedIndex = 0 at the ending

inside the GetQABoxList() subroutine

and make sure there should not be any javascript error shown on ststus bar

i hope it helps

Rohit


Thanks

It work fine with the suggestion you gave.