Showing posts with label user. Show all posts
Showing posts with label user. Show all posts

Wednesday, March 28, 2012

viewstate serialization and atlas

Just testing a little popup calendar user control making use of Atlas. I notice that when I serialize the viewstate unusually (I have a 'StorePage' class that stores the viewstate in the db, keyed on a GUID in a hidden field on the page), the atlas calendar popup fails.

Can I work around this? Do my Atlas pages need to be decended directly from the Page class, or is my GUID-keyed technique flawed?

The calendar uses an updatepanel.

Thanks,

John

Hi John,

Can you explain exactly what doesn't work? Are you registering the hidden field by using ClientScript.RegisterHiddenField?

All pages no matter what will derive from Page, and Atlas doesn't care if there are other intermediate classes in the way (almost all pages have intermediate classes anyway due to code-behind files).

I can't think of any specific reason why this wouldn't work off the top of my head.

Thanks,

Eilon

Monday, March 26, 2012

want collapsiblePanel in user control to remember its state

Hi,

I am using the ajax collapsible panel extender. Is there a way to remember the state of the collapsible panels?...

basically i am using it as part of a side navigation, the sidenavigation is a user control and is used on every webpage of the site. when i click the hyperlinks (contained within the panels that extend) the page navigates to the new page and all the panels collapse. i can see how this can get frustrating to users. so is there a way that it can remember what state it is in??

thanks

Hi,

According to your description, you want to maintain the state of collapsible panels between different pages, isn't it?

In order to implement this, you need to save the state in a place out of the scope of a page, so that it can't be shared among different pages. Cookie, Session, or Profile will be good choices for you.

By default, the state is saved in ViewState or some additional HiddenField. The problem with them is that they are inside a page, and are always transfered to the server with POST http request. When it's redirected to a new page with GET request, those values will not be available in the new page. So, storages that doesn't rely on a specific page should be used.


yes i want it to remember the state across different webpages.

Can you guide me further with what i may need to do?...can i do this by assigning something to a session variable? if so what must i assign?and what must i do to open the new page with the newly assigned state?

thanks


You can save the state in session. For example, Session["cp1State"] = ture; // indicates collapsibelPanel1 is expanded.

Another thing you need to do is use javascript to invoke a web service to save current state in session. This javascript will work as the expanded and collapsed event handler for the corresponding CollapsiblePanelBehavior.


Hello Raymond,

Please can you give further details with the web service i need. i dont really know about web services...are there any examples used in conjunction with collapsiblePanel?

thanks


Here is a sample:

<%@. 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">[System.Web.Services.WebMethod] public static void SaveState(string state) { HttpSessionState session = HttpContext.Current.Session; session["State"] = state; } protected void Page_Load(object sender, EventArgs e) { string script = @."function pageLoad(sender, args) { {0} $find('cpe2Behavior').add_collapsed(onCollapsed); $find('cpe2Behavior').add_expanded(onExpanded); }"; if (Session["State"] != null && Session["State"].ToString() == "expanded") { script = script.Replace("{0}", "$find('" + CollapsiblePanelExtender2.BehaviorID + "').expandPanel();"); } else { script = script.Replace("{0}", ""); } ScriptManager.RegisterStartupScript(this, this.GetType(), "expand", script, true); }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"> </asp:ScriptManager> <asp:Panel ID="panel4" runat="server" > <asp:LinkButton ID="lnk2" runat="server" Text="Show Details"/> </asp:Panel>  <!--Content to show--> <asp:Panel id="panel3" runat="server"> Content </asp:Panel> <ajaxToolkit:CollapsiblePanelExtender SuppressPostBack="true" ID="CollapsiblePanelExtender2" BehaviorID="cpe2Behavior" runat="server" TargetControlID="panel3" ExpandControlID="panel4" CollapseControlID="Panel4" Collapsed="True" TextLabelID="lnk2" CollapsedText="Show Details.." ExpandedText="Hide Details.." > </ajaxToolkit:CollapsiblePanelExtender> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default3.aspx">Redirect to me</asp:HyperLink></div> <script type="text/javascript"> function pageLoad(sender, args) { $find("cpe2Behavior").add_collapsed(onCollapsed); $find("cpe2Behavior").add_expanded(onExpanded); } function onCollapsed(sender, args) { PageMethods.SaveState("collpased"); } function onExpanded(sender, args) { PageMethods.SaveState("expanded"); } </script> </form></body></html>

Saturday, March 24, 2012

Watermark and Popup Calendar issue

David, I download the lastest toolkit, and try the following code in aspx page. It is OK. But when I put it into a user control. It won't work!

The error is caused by code when clicked on popup calender:
var mydate = $("TextBox1").mydate;
The error message is Object is required

<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false" CodeFile="test2.aspx.vb" Inherits="test2" %>
<%@dotnet.itags.org. Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit" %>
<!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">
<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
<div>
<script type="text/javascript" language="javascript">
function commitScript1() {

var mydate = $("TextBox1").mydate;
if("" == mydate) {
mydate = "";
}
$object("TextBoxWatermarkBehavior_TextBox1").set_Text(mydate);
}
</script>
<asp:TextBox ID="TextBox1" runat="server" Width="150"></asp:TextBox>
<asp:Panel ID="Panel4" runat="server" CssClass="popupControl">
<atlas:UpdatePanel ID="UpdatePanel6" runat="server" Mode="Conditional" RenderMode="Block">
<ContentTemplate>
<center>
<asp:Calendar ID="Calendar3" runat="server" BackColor="White" BorderColor="#999999"
CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt"
ForeColor="Black" Width="160px" OnSelectionChanged="Calendar3_SelectionChanged">
<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<SelectorStyle BackColor="#CCCCCC" />
<WeekendDayStyle BackColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#808080" />
<NextPrevStyle VerticalAlign="Bottom" />
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
<TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
</asp:Calendar>
</center>
</ContentTemplate>
</atlas:UpdatePanel>
</asp:Panel>
<atlasToolkit:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender3" runat="server">
<atlasToolkit:TextBoxWatermarkProperties TargetControlID="TextBox1" WatermarkCssClass="watermarked"
WatermarkText="<DD/MM/YYYY>" ID="TextBoxWatermarkBehavior" />
</atlasToolkit:TextBoxWatermarkExtender>
<atlasToolkit:PopupControlExtender ID="PopupControlExtender3" runat="server">
<atlasToolkit:PopupControlProperties TargetControlID="TextBox1" PopupControlID="Panel4"
Position="Bottom" ID="PopControlBehavior1" CommitProperty="mydate" CommitScript="commitScript1()" />
</atlasToolkit:PopupControlExtender> </div>
</form>
</body>
</html
CodeFile:
Partial Class test2
Inherits System.Web.UI.Page
Protected Sub Calendar3_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
PopupControlExtender3.Commit(Calendar3.SelectedDate.ToShortDateString())
Calendar3.SelectedDate = Nothing
End Sub
End ClassI believe this thread addresses the issue you're seeing (hard-coded ID changed by inclusion in a different naming container):http://forums.asp.net/thread/1368445.aspx

Watermark + Textbox Issue

I have a web form with a text box with an associated watermarktextbox extender and a button. The goal is to have the user input a name into the the textbox and then use that value when the button is clicked as parameter to a new web page. This works if i remove the watermarktextbox extender. Any assistance would be appreciated.


Do you want a watermark? What exactly do you want to do? Are you receiving errors?


Sorry for the vague original post. Yes, the goal is to have a watermarked textbox. The user enters data into the textbox and I want to use that data as a parameter to a redirection to a new webpage. The problem is that when I use the watermarked textbox the textbox text is not captured (i.e., my parameter is empty). If I use a standard textbox, I'm able to retrieve the textbox text and use it as I intend. I receive no errors I just get an empty value. I'm guessing I need to change the way I get the value of the textbox (client-side script?) but I have no idea how to do this.

Thanks.


OK. Post the script that your using.


Hi,

It's hard to tell without knowing how do you pass value? Are you using queryString? Or PostBackURL?

Please be more specific, a simple repro is preferred.

Watermark extender type function on a dropdown?

Hi there,

I have 5 textboxes all using the watermark extender to tell the user that these fields are required and has some colour formatting. I would also like to do the same type of thing to a dropdown but it doesn't work, can anyone suggest a method I can use?

Thank you for your time

Here's just one suggestion:

<%@. Page Language="VB" AutoEventWireup="false" CodeFile="Default4.aspx.vb" Inherits="Default4" %><%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><%@. Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %><!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> <script type="text/javascript"> function ddlChange(ddl) { if (ddl.selectedIndex == 0) { ddl.style.backgroundColor = 'Yellow'; ddl.options[0].innerText = 'Please select...'; } else { ddl.style.backgroundColor = ''; ddl.options[0].innerText = ''; } } </script></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:DropDownList ID="DropDownList1" runat="server" style="background-color:Yellow;" onchange="ddlChange(this)"> <asp:ListItem Value="">Please select...</asp:ListItem> <asp:ListItem>Option A</asp:ListItem> <asp:ListItem>Option B</asp:ListItem> <asp:ListItem>Option C</asp:ListItem> </asp:DropDownList> </div> </form></body></html>

Thats cool thank you for that! one question, can css be used in place of hardcoding the color?

Thanks again


Pretty simply really, use the same javascript example as above

Create a new Required style for the dropdown e.g background-color:red; have that as the dropdown list's default css then using this piece of javascript be able to swap between the 2 based on Item value

function ddlChange(ddl)

{
if (ddl.selectedIndex == 0)
{
ddl.className ='RequiredCSS'
}
else
{
ddl.className ='SelectedCSS';
}
}

Hope this helps you out.


awesome thank you

Boy, diverdan, I do all the hard typing and you get all the credit!

Just kidding.

Happy Holidays, all...


Sorry!!!! I thought I had clicked the both of you!

Thank you for your help! have a great holiday!

watermark extender and javascript?

Hi, i have a textbox on the page. When the user clicks on a username in the list to the right i use this javascript to insert their username into the textbox.

function

setTextBoxText(text)
{
var textbox = window.document.getElementById("<%=touser.ClientID%>");
textbox.value ='';
textbox.value = text;
textbox.focus();
}

This works perfectly.

Then i tried to add a TextboxWatermarkExtender and now it does not work anymore, the initial text in the textbox (set by the watermark extender) gets erased, but the username does not show up, it just turns blank and focus is set on the textbox. Is there anyway to fix that?

Patrick

any idea?

I tested this out yesterday and found out that when you use WaterMarked on your textbox, all of the changes to the textbox through javascript will be written to watermarked's layer.

e.g. you have a textbox with onchange or onfocus command to call a javascript function; and the textbox also has a watermarked "Enter Name Here"

Your JavaScript function will insert the user's name into the textbox.

document.getElementById('" & Me.textbox1.ClientID & "').value = 'John Smith';

Problem: What happen is, "Enter Name Here" will be replaced with "John Smith", and the textbox is still empty.


Question, is this a bug or is it as design?

Watermark issue

Case: 2 textboxes connect to popup calendar and watermark.

If there are more than one watermark ccontrol in one user control, there is problem as following:

If you input data for textbox1 using popup calendar, it will clean data in textbox2.
If you input data for textbox2 using popup calendar, it will clean data in textbox1.

But if you type the data in textbox, no this problem.

<atlasToolkit:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" runat="server">
<atlasToolkit:TextBoxWatermarkProperties ID="WaterMark1" TargetControlID="textbox1"
WatermarkText="<Type Batch Name Here>" WatermarkCssClass="watermarked" />
<atlasToolkit:TextBoxWatermarkProperties ID="WaterMark2" TargetControlID="textbox2"
WatermarkText="<DD/MM/YYYY>" WatermarkCssClass="watermarked" />
</atlasToolkit:TextBoxWatermarkExtender>Could you please post a simple, complete sample page that demonstrates the problem?
Sample code here:

<%@. Control Language="VB" AutoEventWireup="false" CodeFile="Edit.ascx.vb" Inherits="Common_Edit" %>
<%@. Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit" %
<asp:Panel ID="Panel1" runat="server" CssClass="popupControl">
<atlas:UpdatePanel ID="UpdatePanel1" runat="server" Mode="Conditional" RenderMode="Inline">
<ContentTemplate>
<center>
<asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="#999999"
CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt"
ForeColor="Black" Width="160px" OnSelectionChanged="Calendar1_SelectionChanged">
<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<SelectorStyle BackColor="#CCCCCC" />
<WeekendDayStyle BackColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#808080" />
<NextPrevStyle VerticalAlign="Bottom" />
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
<TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
</asp:Calendar>
</center>
<atlasToolkit:PopupControlExtender ID="PopupControlExtender1" runat="server">
<atlasToolkit:PopupControlProperties TargetControlID="textbox1" PopupControlID="Panel1"
Position="Bottom" />
</atlasToolkit:PopupControlExtender>
</ContentTemplate>
</atlas:UpdatePanel>
</asp:Panel>
<asp:Panel ID="Panel2" runat="server" CssClass="popupControl">
<atlas:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<center>
<asp:Calendar ID="Calendar2" runat="server" BackColor="White" BorderColor="#999999"
CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt"
ForeColor="Black" Width="160px" OnSelectionChanged="Calendar2_SelectionChanged">
<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<SelectorStyle BackColor="#CCCCCC" />
<WeekendDayStyle BackColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#808080" />
<NextPrevStyle VerticalAlign="Bottom" />
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
<TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
</asp:Calendar>
</center>
<atlasToolkit:PopupControlExtender ID="PopupControlExtender2" runat="server">
<atlasToolkit:PopupControlProperties TargetControlID="textbox2" PopupControlID="Panel2"
Position="Bottom" />
</atlasToolkit:PopupControlExtender>
</ContentTemplate>
</atlas:UpdatePanel>
</asp:Panel
<atlasToolkit:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" runat="server">
<atlasToolkit:TextBoxWatermarkProperties ID="WaterMark1" TargetControlID="textbox1"
WatermarkText="<DD/MM/YYYY>" WatermarkCssClass="watermarked" />
<atlasToolkit:TextBoxWatermarkProperties ID="WaterMark2" TargetControlID="textbox2"
WatermarkText="<DD/MM/YYYY>" WatermarkCssClass="watermarked" />
</atlasToolkit:TextBoxWatermarkExtender
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<atlas:UpdatePanel ID="EditUpdatePanel" RenderMode="Inline" Mode="Conditional" runat="Server">
<ContentTemplate>
<table id="Table11" cellspacing="0" cellpadding="0" border="0"
style="width: 752px">
<tr>
<td>
</td>
<td align="right">
Batch Date:</td>
<td>
<asp:TextBox ID="textbox1" runat="server" CssClass="TextBox" Width="152px"></asp:TextBox></td>
<td align="right">
Deposit Date:</td>
<td>
<asp:TextBox ID="textbox2" runat="server" CssClass="TextBox" Width="152px"></asp:TextBox></td>
</tr>
</table>
</ContentTemplate>
</atlas:UpdatePanel>
</td>
</tr>
</table
This also sounds like the problem I found yesterday with 3 textboxes in a DetailsView InsertItemTemplate. One is connected to a calendar popup, another a plain textbox, and the third is my custom auto complete extender. Clicking in the textbox with the popup calendar clears the watermark in the other 2 textboxes.
Kent, the problem you're hitting seems to be because the PopupControl and TextBoxWatermark that are both pointed to the same TextBox are conflicting. If you remove the TBW, the scenario seems to work fine. I don't currently have a good suggestion for making the two controls work together due to the way that UpdatePanels get involved here. Hope this helps.

Wednesday, March 21, 2012

Web page and User control

Good morning ladies and gents. I need a help with the following scenario:
I have a web page and two user controls.
a web page(ASPX) namedWebPage.aspx
a user control(ASCX) namedUserControl1.ascx
a user control(ASCX) namedUserControl2.ascx

TheWebPage.aspx has a user controlUserControl1.ascx bind to it and then user UserControl1.ascx hasUserControl2.ascx in it.(See below)
InsideUserControl2.ascx page a have a TabContainer control namedTabs. It has a methodOnClientActiveTabChanged="ActiveTabChanged".
ActiveTabChangedis JavaScript function (see below) inside aUserControl2.ascx

function ActiveTabChanged (sender, e)
{
__doPostBack('<%= Tabs.ClientID %>',sender.get_activeTab().get_headerText());
}
So basically when you switch from one TabPanel to another it should do a post back.
My problem is that Java Script function not getting triggered; it is only fires when I put it intoUserControl1.aspx but now facing a problem like "Tabs"control not exist onUserControl1.aspx .

My question is: How can I executeActiveTabChanged function to get a post back?

Thank you for your help.

Are you sure the real Tab.ClientId is written into the client code. You might want to compare what it is actually writting (you can do this with the source view on IE).


Yes, i did compare what's in the view source and it looks fine to me.

Thanks for reply