Showing posts with label text. Show all posts
Showing posts with label text. Show all posts

Wednesday, March 28, 2012

Dynamic controls problem.

dear All

I have a checkbox (dynamically generated) and a label.

when the checkbox is changed, I want to change the labels text property. and also put a dynamic DropDownlist box on thr form.

when the Dropdownlist box selected value is changed, I want to again change the value of the labels text to something else. The checkbox behaves properly, but the DropDownList box when selected doesnt do ANYTHING. NOTE: I put the label in a update panel and call the panel.update() method. I put both the .cs and .aspx codes below.

aspx code

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server"> <ContentTemplate> <asp:PlaceHolder ID="PlaceHolder1" runat="server"> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </asp:PlaceHolder> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>


aspx.cs code

using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partialclass _Default : System.Web.UI.Page { CheckBox CheckBox1 =new CheckBox(); DropDownList Dropdownlist1 =new DropDownList();protected void Page_Load(object sender, EventArgs e) { Label1.Text ="page has loaded"; addCheckBox(); CheckBox1.AutoPostBack =true; ScriptManager1.RegisterAsyncPostBackControl(CheckBox1);//adddropdownlist(); CheckBox1.CheckedChanged +=new EventHandler(CheckBox1_CheckedChanged); Dropdownlist1.AutoPostBack =true; ScriptManager1.RegisterAsyncPostBackControl(Dropdownlist1); Dropdownlist1.SelectedIndexChanged +=new EventHandler(DropDownList1_SelectedIndexChanged); }private void adddropdownlist() { Dropdownlist1.Items.Add("first"); Dropdownlist1.Items.Add("second"); Dropdownlist1.Items.Add("thirs"); PlaceHolder1.Controls.Add(Dropdownlist1); }private void addCheckBox() { CheckBox1.Text ="tickme"; CheckBox1.ID ="checkbox1"; PlaceHolder1.Controls.Add(CheckBox1); }void CheckBox1_CheckedChanged(object sender, EventArgs e) { Label1.Text ="checkbox has been ticked"; adddropdownlist(); UpdatePanel1.Update(); }void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { Label1.Text ="Page has reloaded"; UpdatePanel1.Update(); }}

Thanks in advance,

prasad..

bumping--please help me.

This doesn't have to do with AJAX (try removing the UpdatePanel to see).

I highly recommend this 4-part series on dynamic controls in ASP.NET:http://devsushi.com/2006/08/27/aspnet-dynamic-control-creation-part-1/

The behavior I see with your code is that when I change the dropdown, the page goes back to its initial state ("page has loaded" and a checkbox). This makes sense, because when you change the dropdown, the page posts back, and in that postback, you don't create the dropdown. That means there's no control to hook up to, and the SelectedIndexChanged event doesn't fire. What you need to do is create the dropdown on every postback where you need to use it.

I recommend adding the dropdown to the placeholder in Page_Loadall the time, and setting Dropdownlist1.Visible = false. Then set Dropdownlist1.Visible = true when you want to display it. That way its events will still hook up properly when it causes a postback.

I hope that makes sense, but if it doesn't, the article I pointed to above should help a great deal. This can be confusing.


thank you for the link to the article. now I realise...what really a postback is. This was my first attempt at programming...:)

thank you,

prasad.

Dynamic Change Between 100 Text Labels

Hello there..

I want to use AJAX dynamic lets get started..

I have 100 Quots that i want AJAX to Random select one and display and after 10 Sec. i want i to select another...

Is that possible? and if yes how??

Hope someone know how to do that..

/MJ Out

Please look at the timer control.

http://ajax.asp.net/docs/tutorials/IntroToTimerControl.aspx

Cheers



BenRush:

Please look at the timer control.

http://ajax.asp.net/docs/tutorials/IntroToTimerControl.aspx

Cheers


Ive tried that.. but how do i define more labels?? and make it random select one? sry for asking but im a noob :)


Anyone? :D Come on.. there is many smart heads in here.. one of them have to know how...

*Bump*

anyone? or isnt it possible

Monday, March 26, 2012

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 an UpdatePanel

Hi

When i change the DropDownList value, the Text property doesn't change and the selected index is still at 0.

Did you have the problem ? Can you help me ?

Hi eome,

I use DropDownList on updatePanel and it is working correctly, small example of your code could show more about your problem, can you send it here?

MilKob

PS. Did you try to call Update method on updatePanel after setting new value in dropDownList?


Well, thanks for your answer. I made a mistake, there is no problem ! sorry ! :)

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.

Wednesday, March 21, 2012

Dropdownlist

I have just started using Atlas and I am having a little trouble changing the text of a label when a font is selected from a drop down list. When the font-family name is selected the entire dropdown list is moved into the label. Here is my code

C# code

protected

void Page_Load(object sender,EventArgs e)

{

if (!Page.IsPostBack)

{

DisplayLabel.Style.Clear();FontFamilyDropDownList.DataSource = System.Drawing.FontFamily.Families;

FontFamilyDropDownList.DataBind();

FontFamilyDropDownList.Items.Insert(0,

"Default");

}

}

protectedvoid FontFamilyDropDownList_SelectedIndexChanged(object sender,EventArgs e)

{

DisplayLabel.Text = FontFamilyDropDownList.SelectedValue;

}

ASP Code

<asp:LabelID="DisplayLabel"runat="server"Text="Test Atlas Controls"></asp:Label>

<atlas:UpdatePanelID="FontNameUpdatePanel"Mode="Conditional"runat="server"><Triggers><atlas:ControlEventTriggerControlID="FontFamilyDropDownList"EventName="SelectedIndexChanged"/></Triggers><ContentTemplate>

<asp:DropDownListID="FontFamilyDropDownList"runat="server"DataTextField="Name"OnSelectedIndexChanged="FontFamilyDropDownList_SelectedIndexChanged"AutoPostBack="true"></asp:DropDownList>

</ContentTemplate></atlas:UpdatePanel>

Any suggestions would be great

Thanks

Mike

Figured it out, needed to place the label inside of the ContentTemplate and remove the DropDownList for it to work.

DropDownExtender: How can I set the text of downlist?

Hi,

I need your kindly help.When I try to use DropDownExtender just as following:

<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Always" RenderMode="Inline">
<ContentTemplate>
<cc1:DropDownExtender ID="dropdownextender" runat="server" Enabled="true" TargetControlID="fromTime" DropDownControlID="calender" >
</cc1:DropDownExtender>
<asp:Calendar ID="calender" runat="server" OnSelectionChanged="calender_SelectionChanged" ></asp:Calendar>
<asp:DropDownList ID="fromTime" runat="server" AutoPostBack="false" Width="90%">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="calender" />
</Triggers>
</asp:UpdatePanel>

protected void calender_SelectionChanged(object sender, EventArgs e)
{
fromTime.Text = calender.SelectedDate.ToString();
}

Although I can get the SelectedDate, but formTime.Text is “”all the time.Is there anything wrong? How can I set the text?

Many Thanks&&Best Reguards

Nicorn

Resolved.Big Smile

protected void fromcalender_SelectionChanged(object sender, EventArgs e)
{
fromTime.Items.Clear();
string[] date = fromcalender.SelectedDate.ToString().Split(' ');
fromTime.Items.Add(new ListItem(date[0], date[0]));
}


Big Smile Fixed ^_^

protected void fromcalender_SelectionChanged(object sender, EventArgs e)
{
fromTime.Items.Clear();
string[] date = fromcalender.SelectedDate.ToString().Split(' ');
fromTime.Items.Add(new ListItem(date[0], date[0]));
}

DropDownExtender problem

Hi all...

I have problem with DropDownExtender.

There is on the page have placed DropDownExtender and disabled TextBox Control with some text.

When I make right click on the text in disabled textbox, I get JavaScript error like "Object doesn't support this property or method". (Problem with getClientRects function in Script sources file)

Simple content page:

<%@dotnet.itags.org. Page Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestApp.Default" Title="Untitled Page" %><%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %><asp:Content ID="Content1" ContentPlaceHolderID="cphContent" runat="server"><table cellpadding="0" cellspacing="0" border="0"> <tr> <td align="left"> <asp:Label ID="lblLinkName" runat="server" Font-Size="12px" Text="Show Links" Style="display: block; padding: 2px; padding-right: 20px; color: White;font-size:12px;font-weight:700;font-family: Verdana,Arial, MS Sans Serif, Tahoma;" /> <asp:Panel ID="DropPanel" runat="server" Style="display: none; visibility: hidden; background: White;"> <table cellpadding="2" cellspacing="0" border="0" style="width:150px; border: solid 1px Gray;"> <tr> <td><asp:LinkButton ID="lnkFirst" runat="server" Text="First Link" /></td> </tr> <tr> <td><asp:LinkButton ID="lnkSecond" runat="server" Text="Second Link" /></td> </tr> <tr> <td><asp:LinkButton ID="LinkThird" runat="server" Text="Third Link" /></td> </tr> </table> </asp:Panel> <ajaxToolkit:DropDownExtender runat="server" ID="DDE" TargetControlID="lblLinkName" DropDownControlID="DropPanel" HighlightBackColor="#256294" HighlightBorderColor="white" /> </td> </tr> <tr> <td> </td> </tr> <tr> <td><asp:TextBox ID="txtField" runat="server" Width="200" /></td> </tr></table></asp:Content>
 CodeBehind:
 
using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;namespace TestApp{public partialclass Default : System.Web.UI.Page {protected void Page_Load(object sender, EventArgs e) {if (!Page.IsPostBack) { txtField.Text ="Hello World!"; txtField.Enabled =false; } } }}

Try to reproduse this bug or leave your email and I send example.

Please help.Sad