Showing posts with label dynamically. Show all posts
Showing posts with label dynamically. Show all posts

Wednesday, March 28, 2012

Changing dynamically a user control within an UpdatePanel

I have a page that (using ajax), will dynamically route someone through a bunch of survey questions. Each survey page is written as a user control as each page needs to have a lot of flexibility, etc to visually add/edit HTML, blah, blah, but that's not the problem. I'm having a problem with loading the question too late in the page life cycle, so our respondent will see the following...

Introduction, Q1 (where they answer), Q1 again (as their answers aren't remembered), Q2 (Q1 answers were remembered this time), Q2 (again, cause Q2 answers weren't remembered first time again)... and so on, etc.

I know what the problem is, but I'm drawing a blank on how I can execute what I want properly. I've attached the code for my controlling page below. Thank you for any advice anyone can offer!!!

<%@dotnet.itags.org. Page Language="C#" MasterPageFile="~/survey.master" Title="Surveys" %>
<%@dotnet.itags.org. Import Namespace="SurveyWebControls" %><script runat="server">
const string SurveyStart ="SurveyStart";

SurveyPageBase currentSurveyPage;

protected void Page_PreInit(object sender, EventArgs e)
{
Page.Theme ="SurveyDefault";
}

protected void Page_Load(object sender, EventArgs e)
{
lblErrorMessage.Text ="";

if (txtCurrentSurveyPage.Value =="")
LoadSurveyPage(SurveyStart);
else LoadSurveyPage(txtCurrentSurveyPage.Value); }protected void btnNext_Click(object sender, ImageClickEventArgs e)
{
if (currentSurveyPage.Validated)
LoadSurveyPage(currentSurveyPage.NextPage);
else lblErrorMessage.Text = currentSurveyPage.ErrorMessage; }private void LoadSurveyPage(string QId)
{
Survey.Controls.Clear();
currentSurveyPage = (SurveyPageBase)LoadControl(QId +".ascx");
Survey.Controls.Add(currentSurveyPage);
txtCurrentSurveyPage.Value = currentSurveyPage.QId;
btnNext.Visible = currentSurveyPage.ShowNext;
}

</script
<asp:Content ID="SurveyBody" ContentPlaceHolderID="SurveyBody" Runat="Server">
<asp:UpdatePanel ID="SurveyUpdatePanel" runat="server">
<ContentTemplate>
<asp:HiddenField runat="server" ID="txtCurrentSurveyPage" />
<asp:Label runat="server" ID="lblErrorMessage" SkinID="ErrorMessage" />
<asp:PlaceHolder ID="Survey" runat="server" />
<br /><br />
<asp:ImageButton ID="btnNext" SkinID="NextButton" runat="server" OnClick="btnNext_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
Try to use the template of asp:Wizard to load?user?controls?dynamically.?Try?to?take?a?look?at?the?following?materials?for?details.
http://msdn2.microsoft.com/en-us/library/fs0za4w6(VS.80).aspx
http://aspnet.4guysfromrolla.com/articles/061406-1.aspx
http://support.microsoft.com/kb/180405
http://weblogs.asp.net/sushilasb/archive/2004/03/31/104939.aspx
http://aspalliance.com/766_Working_with_the_Wizard_Control_Using_Visual_Studio_2005

Wish the above can help you.
I had thought of that, but it would still have to be dynamic. Sometimes there are literally hundreds of pages where someone might only go through 5 of them, based on how they answer previous questions.

Change Themes using Ajax

Hi,

I am changing themes dynamically when i am clicking image button. i write a code to change the theme at Page_PreInit().

I need to reload the page to take effect. so i used response.redirect(SamePage.aspx). hope response.redirect is not supported on update panel.

i need to change themes using Ajax( without postback).

Thanks in Advance.

I don't think you can change the theme directly using ajax; but what you can do is change the href on your link tag(s) to give you new stylesheets.


Hi,

I think you dont need to Redirect to the same page to change the theme.

Just put

if(Page.IsPostBack)

GridView1.SkinID ="newskinID" in the Page.PreInit event.

Thanks,

Regards

Aruna


Hi,

My previous reply was to change the Skin of a particular control.

If you want to change the theme u can put this code

if (Page.IsPostBack)

this.Page.Theme ="NewSkinFile"

in the Page.PreInit Event Handler

Regards,

Aruna


Aruna,

Thanks for your response.

This is my code.

protectedvoid Page_PreInit(object sender,EventArgs e)

{

if (Request.Cookies["theme"] !=null)

{

this.Theme = Request.Cookies["theme"].Value.ToString();

}

else

{

this.Theme ="Black";

}

}

protectedvoid ImgGreen_Click(object sender,ImageClickEventArgs e)

{

HttpCookie cook=newHttpCookie("theme");

cook.Value=((ImageButton)sender).CommandName;

cook.Expires =DateTime.MaxValue;

Response.AppendCookie(cook);

string[] path = Request.Path.Split(char.Parse("/"));

Response.Redirect(path[path.Length-1].ToString() );

}

when i click image button, i stored theme name in a cookie. based on a cookie i am loading theme.

Page_PreInit() method never fire after image button click until the page reload ( Page_PreInit() will fire first).

so, i redirected to same page.

It is immediately taking theme.

Actually my problem is the page is get postback even i am using update panel.

you got my point.


Paul,

Thanks.

I referred two sites. Live.com and msn india. they are changing page themes without postback. so, i tried.

If you will get resource, post here.

once again thanks paul.


Hi Nanda,

Have u set the commandName of Image Button to the name of the Theme, as you mentioned cook.Value=((ImageButton)sender).CommandName you are trying to put the name of Command in the cookie.

Regards,

Aruna


Aruna,

I am using 4 themes in my project. so, i put 4 imagebutton in my page. all 4 buttons are sharing one methodImgGreen_Click(). so, based on the command name, i am trapping which button is clicking by the user ( i assigned theme name as command name for all four button.)

Thanks.


As I said before, you can't do it the way you're trying to do it. The ASP.Net 'theme' is a pretty rigid thing, and it's set during the Init cycle, which does not fire if you're using and updatepanel (see the documentation on page lifecycle).

If you want to change the look and feel of your site without postback, the way to do it is to build a CSS-based design, and then swap stylesheets from the client.


Dear,

You have redirected to the same page that's y ur page is posted back.

The major problem in your code is PreInit Fires before the button click event, so u cant modify the theme on click of the button by using this code as preinit fires first so it takes the theme of previous click.


Hi,

Hope u have solved ur problem.

If not then let me know I have a solution of ur problem.

Regards,

Aruna


Is that it ? Is CSS-based design the only way to achieve themes without postbacks ?

Aruna, do you have an alternate solution ?

Thanks

Jai

change FilteredTextBoxExtender filter type dynamically

Hi,

Im trying to change the Filter Type of FilteredTextBoxExtender on a checkbox onClick handler.

(The textBox which is my traget control is also a the target control of an AutoCompleteExtender control).

The user can switch between searching an item by its Number ID or by Its name)

therefore I need to change the type dynamically according to the checked property of a check box.

it works fine until I try to change the valid characters. I get the following exception on client side:

Microsoft JScript runtime error: Sys.ArgumentTypeException: Object of type 'String' cannot be converted to type 'AjaxControlToolkit.FilterTypes'.
Parameter name: value

HTML:

<ajaxToolkit:FilteredTextBoxExtenderID="FilteredTextBoxExtender1"runat="server"BehaviorID="FilteredTextBoxTxtStock"TargetControlID="txtStkNum"FilterType="Numbers, Custom">

</ajaxToolkit:FilteredTextBoxExtender>

  
1function chkNameList_click()2 {34 var autoComplete = $find('AutoCompleteBehavior');5 var TextBoxFilter = $find('FilteredTextBoxTxtStock');67 $get('<%=txtStkNum.ClientID%>').value ="";89if($get('UserContext').checked ==true)//Names10 {11 $get('<%=txtStkNum.ClientID%>').className ="txtStockHeb";//right alignment (text box)12 TextBoxFilter.set_ValidChars("?????????????????????? ");1314 }15else//Numbers16 {17 $get('<%=txtStkNum.ClientID%>').className ="txtStockEng";//left alignment (text box)18 TextBoxFilter.set_FilterType("Numbers");19 }20 }

 Thanks,
Tal

Hi Tal88,

Based on my research , I think your problem is mainly caused by TextBoxFilter.set_FilterType("Numbers");

Below is the FilterTypes,

AjaxControlToolkit.FilterTypes.prototype = {
Custom : 0x1, //1
Numbers : 0x2, //2
UppercaseLetters : 0x4, //3
LowercaseLetters : 0x8 //4
}

So if you want to set the FilterTypes to Custom, you should use TextBoxFilter.set_FilterType(1);

Numbers will be TextBoxFilter.set_FilterType(2);

If the FilterTypes is set to "Custom,Numbers,LowercaseLetters", please use TextBoxFilter.set_FilterType(7); //1+2+4

My Ajax Control Toolkit's version is V10618.

I hope this help.

Best regards,

Jonathan

Monday, March 26, 2012

Change AJAX Slider maximum

Hi:

Is there any easy way to change the Maximum values on a slider control dynamically using Javascript.

I have an application that uses one slider to set the maximum on another slider.

Thanks for any help.

Floydo

Try this:

this.SliderExtender1.Maximum -= 2;this.SliderExtender1.Minimum += 2;// Display max and min values.this.Label1.Text =this.SliderExtender1.Maximum.ToString();this.Label2.Text =this.SliderExtender1.Minimum.ToString();

HTH

Jonathan.


Hi Floydo,

Here is an example that increase the maximum value of slider by 10 using javascript. Please try it:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="SliderExtender.aspx.cs" Inherits="AjaxToolKit_SliderExtender" %><!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>
<style type="text/css">
.myclass {position:relative; background:url("../images/slider_h_rail.gif") repeat-x; width:100px;height:100px;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<input type="button" value="Click" onclick="changeLength();" />
</div>
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
<ajaxToolkit:SliderExtender BehaviorID="slider" ID="SliderExtender1" runat="server" TargetControlID="TextBox1" Minimum="0" Maximum="100" RaiseChangeOnlyOnMouseUp="true" Steps="5" RailCssClass="myclass" HandleImageUrl="../images/edit.gif">
</ajaxToolkit:SliderExtender>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></form>
<script type="text/javascript">
function changeLength()

{

var slider = $find("slider");
var max = slider.get_Maximum();
slider.set_Maximum(max + 10);

}
</script>
</body>
</html>

Hope this helps.

CascadingDropDownProperties - Setting SelectedValue dynamically

I have an application where I am using the CascadingDropDown Lists. I have incorporated a set of them into a control.

I want to add a property to my CascadingDropDownProperties that will set an initial "filter" for my list.

For example, if I were using the sample CDD provided on the website that gives Make, Model, Color in my application, I may want to tell my control to only select foreign or domestic makes. At this point, the control can continue on to do what it needs to.

My web method is calling a MS-SQL stored procedure, and it has an input parameter of foreign/domestic (CarClass) for selecting the available Makes.

My questions on this are as follows:

    How do I set up my CascadingdropDownProperties to add the Foreign/Domestic (CarClass) value?

    How do I set this value in the code-behind?

(I will omit my actual DropDownLists from my code.)

Here is my CascadingDropDown definition:

1 <atlasToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server">
2 <atlasToolkit:CascadingDropDownProperties
3 Category="CarClass"
4 ServicePath="~/wsSelectCar_Data.asmx" />
5
6 <atlasToolkit:CascadingDropDownProperties
7 TargetControlID="ddlMake"
8 Category="Make"
9 PromptText="Please select a Make"
10 ServiceMethod="GetMakes"
11 ServicePath="~/wsSelectCar_Data.asmx" />
12
13 <atlasToolkit:CascadingDropDownProperties
14 TargetControlID="ddlModel"
15 ParentControlID="ddlMake"
16 Category="Model"
17 PromptText="Please select a Model"
18 ServiceMethod="GetModel"
19 ServicePath="~/wsSelectCar_Data.asmx" />
20
21 <atlasToolkit:CascadingDropDownProperties
22 TargetControlID="ddlColor"
23 ParentControlID="ddlMake"
24 Category="Color"
25 PromptText="Please select a Color"
26 ServiceMethod="GetColor"
27 ServicePath="~/wsSelectCar_Data.asmx" />
28 </atlasToolkit:CascadingDropDown>

As you can see, I tried to create a property with the Category "CarClass". My Code-behind has the following to try to set the value:

1 int intCarClass =int.Parse(Session["CarClass"].ToString());
2 this.CascadingDropDown1.TargetProperties[0].SelectedValue = intCarClass.ToString();

This does not seem to work.

Thanks,
Bryan

Hi Bryan,

I'd recommend you switch to a page method and then just check whether or not you should apply the additional filter however you want.

Thanks,
Ted

Can you provide sample code for doing this?

I am not familiar with the "Page" methods.

Thanks.

Saturday, March 24, 2012

CascadingDropDown within an Accordion

I have a functioning CDD that I add dynamically to the page during ON_LOAD. I also have a new Accordion that I declare in the ASCX file. Both of these work fine until I try to put the CDD inside the Accordion. I get the following error:

Couldn't get extender properties on extender . Make sure the ID is spelled correctly and the control is on the page.

With the CDD inside the Accordion, I find the dropdown id using:

tempControl = MyAccordion.FindControl("ddlClientCompany")

item1.TargetControlID = tempControl.UniqueID

When I step thru the code with VS I can see that the control is found and an ID is passed in. But an error is thrown:o my question is: 1) is this a bug? 2) What is the correct procedure to include a CDD within the Accordion?

Here is my full code for when I add the CDD (this works fine outside of the Accordion)...

Dim tempExtenderAs AtlasControlToolkit.CascadingDropDown =New AtlasControlToolkit.CascadingDropDown()

Dim item1As AtlasControlToolkit.CascadingDropDownProperties =New AtlasControlToolkit.CascadingDropDownProperties()

item1.Category ="clientCompanyID"

If item1.Category =""Then item1.Category ="none"

item1.DefaultCompany = bu.default_company_id

item1.PromptText ="-- Select Company --"

item1.ServiceMethod ="GetClientCompanies"

item1.ServicePath ="~/buService.asmx"

Dim tempControlAs DropDownList

tempControl = MyAccordion.FindControl("ddlClientCompany")

item1.TargetControlID = tempControl.UniqueID

tempExtender.TargetProperties.Add(item1)

I'll defer to Ted as Accordion expert, but I'm thinking you don't want UniqueID in "item1.TargetControlID = tempControl.UniqueID". I'd try just ID instead.

Thanks for your reply David,

First let me say that I think Atlas rocks and and glad to be part of the CTP, pain and all. Secondly, I am very excited about how Atlas has effect my application interface design- cool ideas with low overhead to implement...nice job!

I did try some combinations that included the ID instead of the UniqueID...but they didnt work.

Although I never got it to work by adding the Extender dynamically, I was able to get it to work when I fully declared the CDD within the ASCX page. This is a work around in my mind and would be very interested in finding out how to do this properly dynamically.

I am also unable to get the SELECTED_VALUE of the CDD from within the Accordion. I am forced to just parse the query object like so.

' lets try to checkout the form values manually

Dim tempDDLClientCompanyAs DropDownList = MyAccordion.FindControl("ddlClientCompany")

Dim tempDDLClientNameAs DropDownList = MyAccordion.FindControl("ddlClientName")

' This is still not returning a value

'client_name = sec.ScrubData(tempDDLClientCompany.SelectedValue)

'manager_name = sec.ScrubData(tempDDLClientName.SelectedValue)

Dim tempClientCompanyID = tempDDLClientCompany.UniqueID

Dim tempClientNameID = tempDDLClientName.UniqueID

Try

Dim formsCountAsInteger = (Request.Form.Count) - 1

If formsCount <= 0ThenExitTry

Dim countAsInteger = 0

' 1) Grab the values from the request for company and client name

Dim tempField, tempValueAsString

' This is not zero based because the forms collection is not zero based.

For count = 1To formsCount

tempValue =CType(Request.Form.Item(count),String)

tempField =CType(Request.Form.GetKey(count),String)

If tempField = tempClientCompanyIDThen

client_name = tempValue

EndIf

If tempField = tempClientNameIDThen

manager_name = tempValue

EndIf

Next

Catch exAs Exception

EndTry


Hi Matthew,

Are you adding the extender right next to the drop down? If they're in different naming containers than that might explain why it can't find it (i.e. even though you pass in UniqueID, it still wouldn't be able to find a match if it was only looking in its own naming container).

Thanks,
Ted


Thanks for the reply Ted,

Let me try to recall that issue...it was a day or so ago and I have since gotten my head around other items, but I believe I tried several places for the extender. 1) Outside the Accordion, and 2) inside the Accordion within the same pane as the CDD if that is what you mean. I'll pull the code tomorrow and see where I left off. cheers,