Showing posts with label form. Show all posts
Showing posts with label form. Show all posts

Monday, March 26, 2012

How Do I Dynamically Update a TabPanel?

New to Ajax, .net and dotnetnuke. I'm trying to figure out something with TabContainers/TabPanels. I want to be fill some form fields on one TabPanel of a TabContainer based on the selected item in a DropDownList on another TabPanel.

Suppose I have something like the code that follows and wanted to put the selected value from the drop down list on Tab 1 into the text box on Tab 2. How would I do that? I am not sure how to access fields on a sibling tab.

Any help would be greatly appreciated.

<asp:UpdatePanel ID="up1" runat="server">

<cc1:TabContainerID="TabContainer1"runat="server"Visible="false">

<cc1:TabPanelID="TabPanel1"runat="server">

<HeaderTemplate>Tab 1</HeaderTemplate>

<ContentTemplate>

<asp:DropDownListID="shopDropDownList"runat="server"

DataSourceID="ShopsDataSource"DataTextField="text"DataValueField="value"

OnSelectedIndexChanged="shopDropDownList_change"AutoPostBack="true" />

</ContentTemplate>

</cc1:TabPanel>

<cc1:TabPanelID="TabPanel2"runat="server">

<HeaderTemplate>Tab 2</HeaderTemplate>

<ContentTemplate>

<asp:TextBox ID="TextBox1" runat="server" />

</ContentTemplate>

</cc1:TabPanel>

</cc1:TabContainer>

</asp:UpdatePanel>

If you need to do this on the client, something like this should work for you:

<scripttype="text/javascript"language="javascript">function pageLoad() {var ddl = $get("<%=DropDownList1.ClientID %>"); $addHandler(ddl,"change", changeHandler); }function changeHandler(e) {debugger;var ddl = $get("<%=DropDownList1.ClientID %>");var tb = $get("<%=TextBox1.ClientID %>"); tb.value = ddl.value; }</script>
 
-yuriy


Hi bob,

Here is a simple sample. Hope it helps.

ASPX Code

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="TabTest.aspx.cs" Inherits="Tab_TabTest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.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">
</asp:ScriptManager>
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="1">
<ajaxToolkit:TabPanel ID="TabPanel1" runat="server">
<HeaderTemplate>Tab1</HeaderTemplate>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="TabPanel2" runat="server">
<HeaderTemplate>Tab2</HeaderTemplate>
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
</ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

C# Code

using System;using System.Data;using System.Configuration;using System.Collections;using System.Collections.Generic;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 Tab_TabTest : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e) {if (!IsPostBack) { List<int> myList =new List<int>(); myList.Add(1); myList.Add(2);this.DropDownList1.DataSource = myList;this.DropDownList1.DataBind(); } }protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) {this.TabContainer1.ActiveTabIndex = 0;this.Label1.Text =this.DropDownList1.SelectedValue; }}

If I misunderstood you, please let me know.


Hi

the provided code works fine for me (it does asynchronous postback to the server and updates the label).

what do you need to change?

-yuriy


Yes. It helps a lot. Thanks.

How do I change the form id that scriptmanager is referencing?

here's a little more detail...

The app is hosted in a portal environment. The portal appends a "token" number to each form on the page to ensure unique form names (the portal page could have more than one form). For example, if I have <form id="form1"> it will change it to something like <form id="form1_1458">. A javascript error occurs after the page loads saying "'this._form' is null or not an object."

I did a viewsource of the page and I see the following:

 <script type="text/javascript">//<![CDATA[Sys.WebForms.PageRequestManager._initialize('form1_1458', document.getElementById('form1'));Sys.WebForms.PageRequestManager.getInstance()._updateControls([], [], [], 90);//]]></script>

I'm not sure if this is the issue but the scriptmanager is referencing to form1.

What I want to do is force the scriptmanager to get document.getElementById('form1_1458'). How can I accomplish this?

the cz of the problem not tht u have a form name inconveniance its about an html error u can run ur page under firefox successfully

u can fix ur prob by checking the syntax b4 the form tag the body tag or another tag check for html syntax errors like added " or unclosed tags

hope being usefull......


I'm surprised this hasn't caused you issues before. If you think about it the server ID is changed which could throw off all control names and references.

I'm not sure that you can change this at run-time without some serious manipulation to the AJAX framework. My thought is that you could get access to form1 using something like document.forms[0] which will get the first form (without using the ID)

-Damien


where/how do I tell the scriptmanager to use document.forms[0]?


Not sure... from my last post: "I'm not sure that you can change this at run-time without some serious manipulation to the AJAX framework..."

The form reference gets set by the ASP.NET AJAX Framework's client scripts; you don't specify the form. Seehttp://www.asp.net/ajax/documentation/live/overview/ScriptManagerOverview.aspx for more info on the ScriptManager

-Damien


finally figured this one out. Many thanks to http://aspnetresources.com/articles/HttpFilters.aspx

Wednesday, March 21, 2012

How can I tell Scriptmanager to look for a specific form id value?

I'm getting a javascript error. I think it's because the Scriptmanager is looking for 'form1' which isn't the value of the form id on the page. The form id value is 'form1_1458'

I did a view source on the browser and I see this line:

Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));
 

I need the ScriptManager to look for 'form1_1458' How can I force the scriptmanager to do to this?

It queries the ClientID on Page's Form property internally. What does Form.ClientID on your page return, if you try to output that?


i should have mentioned that this .aspx page is hosted within a portal environment (BEA aqualogic). The portal seems to append the _1458 to form1 which in the end makes it form1_1458.

let me see what Form.ClientID outputs.

How can I stop the modal popup from disappearing when a postback occurs?

Hello,

I have a problem.
How can I stop the modal popup from disappearing when a postback occurs.

For example, if I have a button on the modal "form", a click makes it dissappear.

Help!

Thanks!

UPDATE:
I just tried wrapping the postback controls in an updatepanel.

Seems to work so far...this the recommended way?

how can i make ajax work this way?

on my form, clicking on the navigation items on the left of screen will filter/refresh the gridview on the right hand side,

how can i achieve this using Ajax and not let the navigation items to reload themselves? (only the gridview refreshes)

Just make sure you only wrap the content you want to be dynamic with theUpdatePanel. That should be all you need. Start there and let us know if you're not getting what you want.


Thanks flanakin, in my applicaton, the dropdownlist has already been placed outside of UpdatePanel. the whole page reloads because the dropdownlist is "autopostback".

I found 3 lines of code that helped me to stop the whole page reload:

<Triggers>

<asp:AsyncPostBackTriggerControlID="DropDownList1"EventName="SelectedIndexChanged"/></Triggers>

I put the code inside the code of UpdatePanel, it worked, This can also be achieved by setting "Triggers" property of the UpdatePanel in design view