Showing posts with label box. Show all posts
Showing posts with label box. Show all posts

Wednesday, March 28, 2012

dinamically adding a webuser control to a Modal Pop Up Extender

I have a page that has two buttons and a text box on it. It also has a panel named pnlPopUp and an modalpopupextender which has 'pnlPopUp' as the PopupControlID.

If you Click Button1 it will display webusercontrol1 and if you click button2 it will display webusercontrol2.

Each user control has two buttons on tem (btnOK and btnCancel).

The web user controls are added dinamically to the panel when I click button1 or button2 (using Page.LoadControl("~/WebUserControl.ascx") andpnlPopup.Controls.Add(webusercontrol) );

I am trying to fill the text of teh textbox in the page according to which button is clicked on the pop-up (if I click Ok it writes "OK" in the textbox),

but my button events aren′t firing!


P.S.: If I load the controls in the page′s Page_Load and making them visible when I need them it will work fine but I didn′t want to do that because in my actual web site i will have too many user controls.

Here′s the sample code. (I′m using the exact code for both user controls):

==================== Default.aspx=============================

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@dotnet.itags.org. Register src="http://pics.10026.com/?src=~/WebUserControl.ascx" TagName="WebUserControl" TagPrefix="wuc" %
<!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>
<link rel="stylesheet" href="http://links.10026.com/?link=back.css" type="text/css" media="screen" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" EnableViewState="true">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:Button ID="btnPopup" runat="server" Text="PopUp" />

<input type="hidden" runat="server" id="hdnPopUp" />

<asp:Panel ID="pnlPopUp" runat="server" CssClass="modalPopup">
</asp:Panel>

<cc1:ModalPopupExtender ID="mpeTestePopUp" runat="server" TargetControlID="hdnPopUp"
PopupControlID="pnlPopUp" DropShadow="true" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

===========================================================

==================== Default.aspx.cs============================

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;
using AjaxControlToolkit;

public partial class _Default : System.Web.UI.Page
{
WebUserControl ucTestePopUp;

protected void Page_Load(object sender, EventArgs e)
{
}

void Page_Init(object sender, EventArgs e)
{
this.btnPopup.Click += new EventHandler(btnPopup_Click);
}

void btnPopup_Click(object sender, EventArgs e)
{
ucTestePopUp = (WebUserControl)Page.LoadControl("~/WebUserControl.ascx");
this.pnlPopUp.Controls.Add(ucTestePopUp);
this.mpeTestePopUp.Show();
}
}

============================================================

==================== WebUserControl.ascx============================

<%@dotnet.itags.org. Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<table>
<tr>
<td>
<asp:Button runat="server" ID="btnSim" Text="Sim" />
</td>
<td>
<asp:Button runat="server" ID="btnNao" Text="Nao" />
</td>
</tr>
</table>

==================================================================

==================== WebUserControl.ascx.cs============================

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;

public partial class WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}

void Page_Init(object sender, EventArgs e)
{
this.btnSim.Click += new EventHandler(btnSim_Click);
this.btnNao.Click += new EventHandler(btnNao_Click);
}

protected void btnNao_Click(object sender, EventArgs e)
{
((TextBox)this.Parent.FindControl("txtTeste")).Text = "Clicou N?o";
}

protected void btnSim_Click(object sender, EventArgs e)
{
((TextBox)this.Parent.FindControl("txtTeste")).Text = "Clicou Sim";
}
}

=================================================================

Hi,

to handle events you need a control with an event handler to instantiated. If you only load your user control once in the click event handler, the button (textbox) in your user control does not exist on the page when postback caused by this button in user control is processed at the server.

Therefore, as you said you need to load your user control in page_load to handle events.

However, you don't need to load all controls. You just need to remeber which control was created last time and create this single control. You can store this information in the ViewState property.

Once you handled events from controls insode user control you can safely remove it from the page.

ALSO: You need to assign ID to your dynamically loaded user control. Otherwise, you will occasionally get problems with events firing from the second click.

-yuriy
http://couldbedone.blogspot.com

Saturday, March 24, 2012

Derived Textbox Not Recognized as Textbox

Hi All,

I have a derived text box class that inherits directly off of TextBox. I have this textbox on a page, and when I use the TextboxWatermark extender and set the TargetControlID to my textbox's ID Atlas doesn't seem to realize that it's a textbox, but just a control. We surmised this because the extender throws an error on "this.control.get_text();" while it's happy to execute "this.control_getCssClass();"

If I use a regular ASP textbox on the page, the extender is a happy camper. Anybody have any thoughts about this?

Thx.

I am having the same issue with the toolkit samples as well. Did you find a fix or reason for this? I also do not have any the properties available in the property box in VS2005 for any of the Atlas controls. But I can go to the source and enter the properties fine.

Dale


We haven't gotten an answer yet. I'm going to try another avenue and see if I get anywhere. I'll post any results.

Oh man, I can't believe I screwed that up. We added code that checks the type of the control being extended and then tweaks the generated XML type based on that so the client side can talk to the specific type (e.g. Sys.UI.TextBox instead of Sys.UI.Control). Well it looks in a hashtable based on the type of the control. So if they type isn't exact, the lookup fails. Darn.

Anyway, here's how to work around it. You just need to do a simple override of the TextboxWatermarkExtender. If VS starts complaining about the reference to ExtenderControlBase, click on "Microsoft.AtlasControlExtender" in your reference and change "Specific Version" to true. I'm not sure why mine got angry about that, but just in case you see it.

public class MyTextBox : System.Web.UI.WebControls.TextBox { }public class MyTextboxWaterMarkExtender : AtlasControlToolkit.TextBoxWatermarkExtender {protected override string GetClientClassForControl(System.Web.UI.Control control) {if (controlis System.Web.UI.WebControls.TextBox) {return"textBox"; }return base.GetClientClassForControl(control); } }

Hey Shawn,

Thanks for the work around. We'll get to testing it this afternoon.

It's a sweet toolkit and the bugs (aka job securitySmile [:)]) will get worked out.

Deploy Toolkit to Server

Please help!

My development box works gret with the latest toolkit. When I try to deploy to the production server, my popups do not work. I've installed the latest AJAX components per the instructions on the server and copies the latest AjaxControlToolkit.dll to the bin directory. What am I missing?

If this helps:

The ScritManager output from the site that works is:

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

//]]>

The ScritManager output from the site that does not work is missing the //<![CDATA[

Also,

the page that does not work does not have any of the javascript create code from the toolkit.

Any ideas?

Did you modify the web.config properly on the server (should pretty much match your dev machines one...) also on your server make sure you have this entry in it:

<location path="ScriptResource.axd">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
</configuration>

Thats the probable solution if all the installs went well and are properly GACed

Wednesday, March 21, 2012

Default date selection, like a high-lighted box for ajaxToolkit:CalendarExtender

Hi,

Can we do this? Right now when the textbox is clicked, a calendar does pop-up with the sentence at the bottom - Today is - today's date - is there a way to select the day in month, having a blue box around it?

Thanks.

Do you mean have a default date selected in the calendar when the click in the textbox? If so, then Yes. There is aSelectedDate property you can set. You can also change the color to whatever you want using theCssClass="ClassName" and the.ajax__calendar_active property. Seehttp://www.asp.net/AJAX/AjaxControlToolkit/Samples/Calendar/Calendar.aspx for more info. If it is something else that you are trying to accomplish, let me know.

Bebandit