Showing posts with label insert. Show all posts
Showing posts with label insert. Show all posts

Monday, March 26, 2012

developer control --> custom TreeWeb into updatepanel

Hi, i have a classic custom treeweb and i have tried to insert it into atlas updatepanel.

All ok, but there is a little problem... now i explain at you.

When the tree is loading it's all ok , but at every postback the treeweb it loses the css_custom property (cssmouseover, cssdefault, etc...) in every inserted TreeElements

I have a base class control Treeweb where i insert the TreeElement in recursive mode, the custom css comes setting into base class Treeweb and they are save in viewstate (standard custom control), after in the render event of the TreeElements i add the attribute class with specify custom css.

Now with atlas this it seems not work because it lose information on this custom property for every TreeElemen.

How I can to arrange this property and to do it css persistent with atlas?

I have see that i must mapped the custom property in a new class that extend TargetControlPropertiesBase<Control> this is right ?

DetailsView Inside of a Modal Popup

I'm using a DetailsView to insert new records into a database as well as edit existing records. The Modal is called via ModalPopupExtender.Show() when a LinkButton is clicked and then hidden when the LinkButtons on the DetailsView are clicked. The Functions of the modal popup seem to work fine as well as the Insert() Update() methods of the DetailsView. The problem I'm having is with updating the Text property of the LinkButton at the bottom of the DetailsView to change it from "Add" to "Save" depending on the DetailsView.CurrentMode that I'm changing to/from. I've tried using Update Panels around the LinkButtons only in the DetailsView and then I added an AsyncPostBack trigger for the LinkButton that pops the modal DetailsView in Insert mode and an AsyncPostBack that pops the modal DetailsView in Edit mode from the GridView I have on the page. Then I added a PostBack trigger to handle clicks of the LinkButton on the DetailsView for Insert/Update (depending on the mode) and then Cancel. Both of the postbacks close the modal successfully, it's the AsyncPostBacks that are not updating the Modal DetailsView to show the right Text on the one LinkButton I'm trying to update. Any help would be appreciated. Here is the code:

1protected void Page_Load(object sender, EventArgs e)2 {34 }5protected void AddCategory_OnClick(object sender, EventArgs e)6 {7 ModalPopupExtender1.Show();8 CategoryDetailsView.ChangeMode(DetailsViewMode.Insert);910 }11protected void UpdateInsert_OnClick(object sender, EventArgs e)12 {13if (CategoryDetailsView.CurrentMode == DetailsViewMode.Insert)14 {15 CategoryDetailsView.InsertItem(true);16 }17if (CategoryDetailsView.CurrentMode == DetailsViewMode.Edit)18 {19 CategoryDetailsView.UpdateItem(true);20 }21 }22protected void Cancel_OnClick(object sender, EventArgs e)23 {24 ModalPopupExtender1.Hide();25 CategoryDetailsView.ChangeMode(DetailsViewMode.ReadOnly);2627 }28private LinkButton updateinsertbtn29 {30get31 {32 LinkButton udtisrtbtn;33 udtisrtbtn = (LinkButton)CategoryDetailsView.FindControl("UpdateInsertLinkBtn");34return udtisrtbtn;35 }36 }37private int index38 {39get40 {41return CategoryGridView.SelectedIndex;42 }43 }44protected void CategoryGridView_OnSelectedIndexChanged(object sender, EventArgs e)45 {46 CategoryDetailsView.ChangeMode(DetailsViewMode.Edit);47if (index != -1)48 {49 ModalPopupExtender1.Show();50 CategoryGridView.DataSourceID =null;51 CategoryTableAdapter categoryAdapter =new CategoryTableAdapter();52 CategoryGridView.DataSource = categoryAdapter.GetCategories();53 CategoryGridView.SelectedIndex = index;54int categoryid = Convert.ToInt32(((Categories.CategoryDataTable)CategoryGridView.DataSource).Rows[CategoryGridView.SelectedRow.DataItemIndex]["CategoryID"]);55 SqlDataSource1.SelectCommand ="Select CategoryName, CategoryDescription, CategoryID from Category where CategoryID = " + categoryid;5657 CategoryDetailsView.DataBind();58 CategoryGridView.DataSource =null;59 CategoryGridView.DataSourceID ="SqlDataSource1";60 SqlDataSource1.SelectCommand ="Select CategoryID, CategoryName, CategoryDescription from Category Order by CategoryName";61 CategoryGridView.DataBind();6263 }64 }

<asp:ContentID="Content1"ContentPlaceHolderID="maincontent"Runat="Server">
<script>
function okScript()
{
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm._doPostBack('UpdatePanel1','');
}
</script>
<asp:ScriptManagerid="ScriptManager1"runat="server"></asp:ScriptManager>
<table>
<tr>
<tdvalign="top"style="padding:5px;line-height:1.6em;">

<asp:HyperLinkID="AddCatLinkButton"runat="server"Text="Add New Category"NavigateUrl="javascript:NewCategory('addCategory.aspx');"></asp:HyperLink><br/>

<asp:LinkButtonID="AddCategoryLinkButton"runat="server"Text="Add New Category"OnClick="AddCategory_OnClick"></asp:LinkButton>

</td>

<tdvalign="top">

<asp:UpdatePanelid="UpdatePanel1"runat="server"UpdateMode="Conditional">

<contenttemplate>

<asp:GridViewid="CategoryGridView"runat="server"DataSourceID="SqlDataSource1"CellPadding="3"DataKeyNames="CategoryID"AutoGenerateColumns="False"OnSelectedIndexChanged="CategoryGridView_OnSelectedIndexChanged">

<Columns>

<asp:CommandFieldHeaderText="Edit"ShowSelectButton="true"SelectText="Edit"/>

<asp:BoundFieldDataField="CategoryID"HeaderText="CategoryID"InsertVisible="False"ReadOnly="True"SortExpression="CategoryID"Visible="False"/>

<asp:BoundFieldDataField="CategoryName"HeaderText="Name"SortExpression="CategoryName"/>

<asp:BoundFieldDataField="CategoryDescription"HeaderText="Description"SortExpression="CategoryDescription"/>

<asp:TemplateFieldHeaderText="Remove Category">

<ItemTemplate>

<asp:LinkButtonID="DeleteButton"runat="server"Text="Remove"CommandName="Delete"></asp:LinkButton>

</ItemTemplate>

<ItemStyleHorizontalAlign="Center"/>

</asp:TemplateField>

</Columns>

<EmptyDataTemplate>

There are no categories to display.

</EmptyDataTemplate>

</asp:GridView>

</contenttemplate>

</asp:UpdatePanel>

</td>

</tr> </table>

<asp:PanelID="CategoryPanel"runat="server"GroupingText="Product Category"Style="display:none;"CssClass="modalPopup">

<asp:DetailsViewID="CategoryDetailsView"runat="server"AutoGenerateRows="False"DataKeyNames="CategoryID"DefaultMode="ReadOnly"

DataSourceID="SqlDataSource1"CellPadding="3"CssClass="TextBox"OnModeChanged="CategoryDetailsView_OnModeChanged">

<Fields>

<asp:BoundFieldDataField="CategoryID"HeaderText="CategoryID"InsertVisible="False"

ReadOnly="True"SortExpression="CategoryID"Visible="False"/>

<asp:BoundFieldDataField="CategoryName"HeaderText="Name"SortExpression="Name"/>

<asp:BoundFieldDataField="CategoryDescription"HeaderText="Description"

SortExpression="Description"/>

</Fields>

<FooterTemplate>

<asp:UpdatePanelID="LinkUpdate"runat="server"EnableViewState="true"UpdateMode="Always"RenderMode="Inline">

<ContentTemplate>

<asp:LinkButtonID="UpdateInsertLinkBtn"runat="server"Text="Test"OnClick="UpdateInsert_OnClick"></asp:LinkButton>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTriggerControlID="AddCategoryLinkButton"EventName="Click"/>

<asp:AsyncPostBackTriggerControlID="CategoryGridView"EventName="SelectedIndexChanged"/>

<asp:PostBackTriggerControlID="UpdateInsertLinkBtn"/>

<asp:PostBackTriggerControlID="CancelButton1"/>

</Triggers>

</asp:UpdatePanel>

<asp:LinkButtonID="CancelButton1"runat="server"Text="Cancel"OnClick="Cancel_OnClick"></asp:LinkButton>

</FooterTemplate>

</asp:DetailsView>

<divalign="center">

<asp:LinkButtonID="OkButton"runat="server"></asp:LinkButton> <asp:LinkButtonID="CancelButton"runat="server"></asp:LinkButton>

</div>

</asp:Panel>

<ajaxToolkit:ModalPopupExtenderID="ModalPopupExtender1"runat="server"TargetControlID="AddCatLinkButton"CancelControlID="CancelButton"OkControlID="Okbutton"

PopupControlID="CategoryPanel"OnOkScript="okScript()"BackgroundCssClass="modalBackground"DropShadow="true">

</ajaxToolkit:ModalPopupExtender>

<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:IT_ASSETDbase %>"

DeleteCommand="DELETE FROM [Category] WHERE [CategoryID] = @dotnet.itags.org.CategoryID"

InsertCommand="INSERT INTO [Category] ([CategoryName], [CategoryDescription]) VALUES (@dotnet.itags.org.CategoryName, @dotnet.itags.org.CategoryDescription)"

SelectCommand="SELECT 'javascript:NewCategory(''editCategory.aspx?CategoryID=' + CAST(CategoryID AS nvarchar) + ''');' AS URL, CategoryID, CategoryName, CategoryDescription FROM Category"

UpdateCommand="UPDATE [Category] SET [CategoryName] = @dotnet.itags.org.CategoryName, [CategoryDescription] = @dotnet.itags.org.CategoryDescription WHERE [CategoryID] = @dotnet.itags.org.CategoryID">

<DeleteParameters>

<asp:ControlParameterControlID="CategoryGridView"Name="CategoryID"PropertyName="SelectedValue"Type="Int32"/>

</DeleteParameters>

<UpdateParameters>

<asp:ParameterName="CategoryName"Type="String"/>

<asp:ParameterName="CategoryDescription"Type="String"/>

<asp:ParameterName="CategoryID"Type="Int32"/>

</UpdateParameters>

<InsertParameters>

<asp:ParameterName="CategoryName"Type="String"/>

<asp:ParameterName="CategoryDescription"Type="String"/>

</InsertParameters>

</asp:SqlDataSource>

</asp:Content>

">

I was unable to accomplish changing the Text property value to what I wanted but I ended up modifying the code to remove the Update Panels in order to get modal DetailsView to Insert and Edit records and then update the GridView control by calling GridView.DataBind() after the Update() or Insert() methods were called for the DetailsView. Not exactly what I wanted but works.

DetailsView & ObjectDataSource: Cancel Insert but Retain User Input

Hi,

I need to cancel an insert operation during a DetailsView/ObjectDataSource insert event, and display to the user the same insert page with their previously entered values. For example, after a server side input validation the user may need to modify some of the values they entered.

Canceling insert is easy in the ObjectDataSource.Inserting event handler: e.Cancel = true;

However, this cancels insert mode and the values the user input are lost. The ObjectDataSource.Inserting event handler has access to the input parameters, which contain the values the user has entered. It is possible to put the DetailsView object back into insert mode: DetailsView1.DefaultMode = DetailsViewMode.Insert; but I don't know how to programatically assign the user values to the fields, since I do not know how to get a handle to the field.

How does one retain the user input values in insert mode when canceling an inserting event in the DetailsView/ObjectDataSource programming model?

Thanks,

Paul

You should validate the input values in the DetailsView ItemInserting event, rather than in the ObjectDataSource Inserting event. In such case the input values will be retained though you cancel the inserting event

protected void DetailsView1_ItemInserting (object sender, DetailsViewInsertEventArgs e)
{
// validate
e.Cancel = true;
}

Thanks

-Mark post(s) as "Answer" that helped you

Wednesday, March 21, 2012

Declarative xml-script from UpdatePanel

Is there a way to insert (and execute) declarative xml-script from UpdatePanel?

For example following code works if control is visible, so xml-script is loaded with the page. If control is hidden, or created at run time xml-script is not executed.

test.aspx:

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" %>
<%@dotnet.itags.org. Register TagPrefix="uc" TagName="Control1" src="http://pics.10026.com/?src=~/WebUserControl.ascx" %>
<script runat="server">
void Button1_Click(object sender, EventArgs e)
{
c1.Visible = true;
}
</script>

<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="ScriptManager" runat="server" EnablePartialRendering="true" />

<atlas:UpdatePanel ID="p1" runat="server" Mode="Conditional">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<uc:Control1 ID="c1" runat="server" Visible="false" />
</ContentTemplate>
</atlas:UpdatePanel>

</form>
</body>
</html>

WebUserControl.ascx:

<%@dotnet.itags.org. Control Language="C#" ClassName="WebUserControl" %>

<div id="panel">Click the button to Hide me</div>
<input id="hideButton" type="button" value="Hide" />

<script type="text/xml-script">
<page xmlns="http://schemas.microsoft.com/xml-script/2005">
<components>
<control id="panel" />
<button id="hideButton">
<click>
<setProperty target="panel" property="visible" value="false" />
</click>
</button>
</components>
</page>
</script>

hello.

well, where's your panel control? if it's inside a user control, then you've already found your problem: the user control is a naming container class. this means that controls declared inside it will have a different client side id (it will be composed by the usercontrol id and the control id).


I thought client side id only changed for webform controls. This panel is just a plain <div>.

And if I just make user control visible from the start, it works, xml-script executes.


hello.

yes, if it's an html control, then you're right. not sure about the visibility...can you show me the div declaration that you have in the user control?


The div declaration is actually in the code above:<div id="panel">Click the button to Hide me</div>

I choose to hide div just for sample sake, it can be any xml-script.

Anyway, I recall now, javascript doesn't execute either, when it's inside control template and then the control instantiated inside update panel. The only way is to use RegisterXYZScript(...). But RegisterXYZScript(...) doesn't work for xml-script.

When using ScriptManager RegisterControl it places xml-script inside of that <xmlScript> tag at the end of update panel's <delta> response. I think it executes it, but there beside RegisterControl I didn't find any more methods to generate xml-script.

I know there is a way to write an ExtenderControl, and use ScriptTextWriter to generate xml-script. I haven't tried that yet.