Wednesday, March 28, 2012

Change event in Ajax Update Panel

Dear All

If any event contains inside of the update panelthen after post back focus is lost. More clearly, LetTextbox1 and TextBox2 inside of the update panel.TextBox1 containsTextChanged event andthis event contains TextBox2.Focus(). But after post back it lost the focus.


Thanks

Aminul Bari

It should work just fine. Let me see if I understand what you are saying:

You've got an updatepanel.


Try to use SetFocus of ScriptManager

http://www.asp.net/AJAX/Documentation/Live/mref/O_T_System_Web_UI_ScriptManager_SetFocus.aspx


Thanks. Its working fine.

Change element on click

Hi,

I'm trying to create an AJAX-enabled control thas has the following functionality:

it's a Label that, when clicked, changes into a TextBox. The user can enter some text into the textbox en when he clicks outside the box (onblur) the textbox changes to a label again (now containing the entered text).

For this I created a server control inheriting from Label and a corresponding client control

The question is: can I change the displayed control in the _onClick event of the client control.

It should be something like:

_onClick : function(e){
this.element = $create(TextBox);
},

Does anyone know the right methods for this?

Thanks,

Thomas

Hmmm... I don't know if you can replace a control like that really. In that case, you would have to go to the parent element in the DOM tree, remove the label element and then add the text element. But that's very cumbersome.

What if you create both Label and TextBox and you toggle visibility on the two? Try changing the css attribute "display". Set it to block to show the element and none to hide it. Could help you with code in case you get stuck, just let me know. Good luck!

Change dropdown selectedvalue in usercontrol, in a page.aspx

Hello,

i have a usercontrol (reservas.ascx) with one dropdown list (dropHoteis) inserted in one masterPage.
In my default.aspx, that is a content page of that masterPage...
How can i change the selected value in the dropdown list (dropHoteis) from my default.aspx?

1. In reservas.ascx, i put the Class Public...
2. In Default.aspx.vb, how can i reference the reservas.ascx?? I tryed, but not appear in my @dotnet.itags.org.Imports... why?

Thanks for your help!

From the page you can useMe.Master.FindControl("IdOfUserControl") which will get you the reference to your user control.

-Damien


Hep, ok...

But in my UserControl how can i declare the "function/property" to change the selectedValue of the dropdownlist??

Example:

Public Property DropSelectedValue(ByVal hotelAs String)Set(ByVal value) dropHoteis.SelectedValue = valueEnd Set Get dropHoteis.SelectedValue = hotelReturn dropHoteis.SelectedIndexEnd Get End Property

This not work for me!! :(

throw: Object reference not set to an instance of an object!!


in the usercontrol's code behind write a public property in which you have to set the dropdown list's value. u can then access that property from your page.aspx using the usercontrol name and can set the value of the dropdown list.

Regards & have a nice day ahead

Change default view of CalendarExtender

I need to change the default calendar view from Days to Years when it initially pops up. Does anybody know how to do this?

Hi Arjang,

me@.arjang.ca:

I need to change the default calendar view from Days to Years

Would you please give us more clear explanations?Do you want to list all the Days of a year on the page? If yes , I think you'd better use javascript + HTML to write your own calendar.As far as I know, the CalendarExtender is designed for showing the Days of a month. For more details, please visit: http://www.asp.net/AJAX/Control-Toolkit/Live/Calendar/Calendar.aspx or the Ajax ControlToolkit's source code.Thanks.

Best regards,

Jonathan


Hi Jonathan

I wanted to have the ability to change the default calendar view from Days to Years when it initially pops up. One real world scenario when this would be very important would be when using the calendar to select a birthdate. The year could be 1950 so it's not practical for someone to scroll back month by month, and users don't always understand they have to click the title twice to switch to year. Exposing a property like "InitialView" that could be set at design time or runtime would be ideal. The calendar would pop up right to year selection, then month, then day.

Anyway, I fixed it by changing the Ajax source code and it seems it is working properly.

Thanks,

Arjang



I would be very interested in doing this as well, what did you change?(in CalendarBehavior.js?)

Also, I would like to fire the date selected event when the user selects a month rather than a day.

Any help would be appreciated.


I did the following changes:

1. added another parameter for default mode:

this._defaultMode ="days";

this._mode =this._defaultMode;

2. expose a property to handle default mode:

get_defaultMode :function() {returnthis._defaultMode;},

set_defaultMode :function(value) {

if (this._defaultMode != value) {

this._defaultMode = value;

this._mode =this._defaultMode;this.raisePropertyChanged("defaultMode");

}

},

3. in hide function change "days" tothis._defaultMode

this._switchMode(this._defaultMode,true);

4. finally, in_switchMonth function add the following code in the else section of "if (this._animated && !dontAnimate)".

if (this._mode !="days")

{

var element =this._modes[this._mode];

$common.setLocation(element, {x:0,y:0});

$common.setVisible(element,true);

}

Hope it helps! please let me know if you face any problem.


Worked like a charm. Thanks so much.

Change datasource for a datagrid using ajax

Hi ppl,

I have a datagrid with XML's as a source file. I have a combo box in the same page and when a user selects a value from the combo box i want to display different stats data without doing a normal postback. I am still learning the updatepanel Ajax control . Can anyone please guide me what i should i do to achieve the functionality? do i need to write any function in js ?

Any help much appreciated

thanks

Place the UpdatePanel around the DataGrid and the Combobox. Make sure the combobox do a postback, set the Autopostback attribute to true. Hook up to the OnSelectedIndexChanged event and get the data based on the selected value and bind it to the DataGrid. When a control inside a UpdatePanel will do a postback, the content of the UpdatePanel will be updated.

If you layout of you page don't allow a UpdatePanel around your combobox, you can instead add a async. postback trigger to the UpdatePanel that will listen to a control's event and update the panel.


Hi Thanks for the response. I placed as the gridview control in the updatepanel and used async trigger as you mentioned. when i changed the dropdownlist the grid doesnt appear at all.

Here is the script and code:

<

divID="Panel1"style="width: 568px; position: static; height: 180px; background-image: url(images/bg-nav.png);">

<spanstyle="color: #ffffff"><strong>

Select L :

</strong></span><asp:DropDownListID="DropDownList1"runat="server"Width="134px"AutoPostBack="True"OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1"><asp:ListItemSelected="True"Value="1">yes</asp:ListItem><asp:ListItemValue="2">no</asp:ListItem></asp:DropDownList><br/><asp:UpdateProgressID="UpdateProgress1"runat="server"AssociatedUpdatePanelID="test"><ProgressTemplate><divstyle="color: #ffffff; background-color: transparent"><imgsrc="images/indicator.gif"/>

Updating ....

</div></ProgressTemplate></asp:UpdateProgress><asp:UpdatePanelID="test"runat="server"><ContentTemplate><asp:GridViewID="GridView1"runat="server"ForeColor="Silver"BorderColor="LimeGreen"BorderStyle="Inset"AutoGenerateColumns="True"><AlternatingRowStyleBackColor="LightSkyBlue"ForeColor="#404040"/></asp:GridView></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="DropDownList1"EventName="SelectedIndexChanged"/></Triggers></asp:UpdatePanel>

Code:

ProtectedSub DropDownList1_SelectedIndexChanged1(ByVal senderAsObject,ByVal eAs System.EventArgs)If DropDownList1.SelectedValue = 1ThenDim myDataSetAsNew DataSet()

myDataSet.ReadXml(Server.MapPath(

"test1.xml"))

GridView1.DataSource = myDataSet

GridView1.DataBind()

ElseDim myDataSetAsNew DataSet()

myDataSet.ReadXml(Server.MapPath(

"test2.xml"))

GridView1.DataSource = myDataSet

GridView1.DataBind()

EndIf

EndSub

When i give wrong XML File name, it comes up with the message saying that it cant find the xml file. Is it something i missing in grid control?

Any help much appreciated?


I copied your code, created 2 example XML files, and everything worked fine for me. When I select a value the GirdView was displayed with the correct XML file.

Hi Fredreik

Can you post your sample XML files? I tried using without AJAX functionality and its working fine :(

thanks


I can't think it has anything to do with your XML files, btw do you use the ASP.Net Ajax version 1.0 RTM, becuase your code runs on my machine with no problems at all so I can't see why it shouldn't work on yours.. maybe you have some more code that I don't have.. I only copy the code you posted.. mabye you do something in code-behind etc..!?

Change contents of an external update panel from within a seperate accordian panel?

I am trying to update the contents of an update panel from the event of changing the panel in the accordian control (located outside of the update panel I wish to update). When I try to creat a trigger the update panel does not see the button located inside the accordian control. Any suggestions?

Let me see if I can clarify my question further. I have a content container on a master page. Inside the content container I have a table with two cells. In the first cell I have am using the accordian control. when I click on one of the headers in the accordian control I want it to update an update panel in cell number 2. The content of the accordian panel will be just a brief headline and overview of what is displayed in the update panel in cell #2. My issue is that when trying to define triggers in the update panel in cell #2 it does not see any of the controls in cell #1. Any suggestions?

Thanks for any help you can provide.

Change content pages of Master Page without Master Page posting back?

so Master + content pages seems like exactly what I want except that they are assembled on postbacks. I am trying to make a site where both Master and Content pages have updatepanels, and the site switches content pages (40+ content pages) without the master page refreshing. Master Pages are assembled on postbacks so I don't think simple master page will work without annoying postbacks. I tried an approach where load content pages inside an Iframe, but the content pages take too long to load becuase each content page loads its own scriptmanager. View/Multiview will probably work but difficult to develop a 40 view multiview, I would rather develop 40 separate aspx pages. Any ideas on making any of these three approaches work well? either fix masterpage postback, or fix Iframe load times, or fix View/Multiview eaase of development?

THanks!

Todd Wilder

I think you are looking at the problem backwards - you have to change the MasterPage of the content page. this.Page.MasterPageFile property.

Another option which I successfuly have deployed is dynamically loading a usercontrol into a placeholder on the masterpage.