Link to home
Start Free TrialLog in
Avatar of jazzIIIlove
jazzIIIloveFlag for Sweden

asked on

converting the frontend in a way, postback works

Hi;

I have a rather complex form that I need to convert in a way that once a controller is clicked, i want a postback action happens that I can check what controller is clicked.

When the user clicks on "Add New", another windows content is appearing below the grid.

I can change return false to return true below which is fine for postback but then I lose the form and it goes into a state as if "Add New" button is not clicked.

Can you help me?

<%@ Control Language="C#" AutoEventWireup="true" Inherits="jazziiiloveWebApplication.UI.ExperimentGroup.News_News" Codebehind="News.ascx.cs" %>
<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>
<%--<asp:UpdatePanel ID="upAB" runat="server">
    <ContentTemplate>--%>
<script type="text/javascript">
    function HideMessage() {
        $('#<%=lblMessage.ClientID %>').fadeOut("medium");
    }

    function HideEditForm() {
        $("#<%=EditForm.ClientID %>").fadeOut("slow");
        ClearAll();
        return false;
    }

    function ShowEditForm() {
        $("#<%=EditForm.ClientID %>").fadeIn("slow");
        ClearAll();

        $("#<%=trPicture.ClientID %>").attr("style", "display:none");

        return false;
    }

    function ClearAll() {
        var lblMessage = document.getElementById("<%=lblMessage.ClientID %>");
        lblMessage.innerHTML = "";

        document.getElementById("<%=txtTitle.ClientID %>").value = "";
        document.getElementById("<%=txtShortDescription.ClientID %>").value = "";
        document.getElementById("<%=txtDescription.ClientID %>").value = "";
        document.getElementById("<%=txtLink.ClientID %>").value = "";
        document.getElementById("<%=hfEditID.ClientID %>").value = "0";

        HideMessage();
    }
</script>
<table width="100%">
    <tr>
        <td>
            <h3>
                <asp:Literal ID="ltrnews" Text="<%$Resources:Swedish,News %>" runat="server">
                </asp:Literal></h3>
        </td>
        <td align="right">
            <asp:Button ID="btnAddNew" runat="server" Text="<%$Resources:Swedish,add %>" OnClientClick="return ShowEditForm()" />
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <hr />
        </td>
    </tr>
</table>
<asp:Label ID="lblMessage" runat="server" CssClass="success_msg"></asp:Label>
<asp:HiddenField ID="hfEditID" runat="server" Value="0" />
<div style="height: 3px">
</div>
<table>
    <tr>
        <td>
            <asp:Literal ID="Literal12" Text="<%$Resources:Swedish,language %>" runat="server">
            </asp:Literal>:&nbsp;
            <asp:DropDownList ID="drpGridLanguage" runat="server" AutoPostBack="true" OnSelectedIndexChanged="drpGridLanguage_SelectedIndexChanged">
            </asp:DropDownList>
        </td>
    </tr>
    <tr>
        <td>
            <asp:GridView ID="grdControl" runat="server" AutoGenerateColumns="False" SkinID="GridAdmin"
                OnRowCommand="grdControl_RowCommand" OnRowDataBound="grdControl_RowDataBound"
                AllowPaging="True" PageSize="10" OnPageIndexChanging="grdControl_PageIndexChanging"
                CssClass="AdminGrid">
                <Columns>
                    <asp:TemplateField HeaderText="<%$Resources:Swedish,Title1 %>">
                        <ItemTemplate>
                            <asp:Label ID="lblNewsTitle" runat="server"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="Link" HeaderText="<%$Resources:Swedish,Link %>" />
                    <asp:TemplateField>
                        <ItemTemplate>
                            <table>
                                <tr>
                                    <td>
                                        <asp:ImageButton ID="btnEdit" runat="server" CommandName="Modify" CommandArgument='<%#Eval("NewsID") %>'
                                            ImageUrl="~/App_Themes/default/images/edit_ico.png" CausesValidation="false"
                                            Style="float: right" />
                                    </td>
                                    <td>
                                        <asp:ImageButton ID="btnDelete" runat="server" CommandName="Remove" CommandArgument='<%#Eval("NewsID") %>'
                                            ImageUrl="~/App_Themes/default/images/delete_ico.png" CausesValidation="false"
                                            OnClientClick="return confirm('Are you sure wants to delete?')" Style="float: right" />
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <EmptyDataTemplate>
                    <asp:Literal ID="ltrnof" Text="<%$Resources:Swedish,record %>" runat="server">
                    </asp:Literal>
                </EmptyDataTemplate>
            </asp:GridView>
        </td>
    </tr>
</table>
<div style="height: 15px">
    <hr />
</div>
<div id="EditForm" runat="server" style="display: none; border: 1px solid #ccc; margin-bottom: 10px;">
    <table cellpadding="3" cellspacing="3" style="background-color: #fff;">
        <tr>
            <td colspan="4">
                <asp:ValidationSummary ID="vsCategory" runat="server" ValidationGroup="ManageNews" />
            </td>
        </tr>
        <tr>
            <td>
                <asp:Literal ID="ltrtlt" Text="<%$Resources:Swedish,Title %>" runat="server">
                </asp:Literal>
            </td>
            <td>
                <asp:TextBox ID="txtTitle" runat="server" CssClass="textnew"></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvTitle" runat="server" ControlToValidate="txtTitle"
                    ErrorMessage="<%$Resources:Swedish,entertlt %>" Text="*" ValidationGroup="ManageNews"></asp:RequiredFieldValidator>
            </td>
            <td>
                <asp:Literal ID="Ltrcat" Text="<%$Resources:Swedish,Category1 %>" runat="server">
                </asp:Literal>
            </td>
            <td>
                <asp:DropDownList ID="drpCategory" runat="server" CssClass="textnew">
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Literal ID="Literal1" Text="<%$Resources:Swedish,Link1 %>" runat="server">
                </asp:Literal>
            </td>
            <td>
                <asp:TextBox ID="txtLink" runat="server" CssClass="textnew"></asp:TextBox>
                <asp:RegularExpressionValidator ID="revLink" runat="server" ControlToValidate="txtLink"
                    ErrorMessage="<%$Resources:Swedish,linkofref %>" Text="*" ValidationExpression="http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&amp;=]*)?"
                    ValidationGroup="ManageNews">*</asp:RegularExpressionValidator>
            </td>
            <td>
                <asp:Literal ID="Literal2" Text="<%$Resources:Swedish,Video %>" runat="server">
                </asp:Literal>
            </td>
            <td>
                <asp:FileUpload ID="fuVideo" runat="server" />
                <asp:Button ID="btnVideoUpload" runat="server" Text="<%$Resources:Swedish,Upload %>"
                    OnClick="btnUploadVideo_Click" ValidationGroup="UploadVideo" />
                <asp:RegularExpressionValidator ID="revVideo" runat="server" ControlToValidate="fuVideo"
                    ErrorMessage="<%$Resources:Swedish,plzvideo %>" ValidationExpression="(.*?)\.(flv|mp4)$"
                    ValidationGroup="UploadVideo">
                </asp:RegularExpressionValidator>
                <br />
                <span class="HelpText">
                    <asp:Literal ID="Literal10" Text="<%$Resources:Swedish,Uploadfl %>" runat="server">
                    </asp:Literal></span>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Literal ID="Literal3" Text="<%$Resources:Swedish,sdescription %>" runat="server">
                </asp:Literal>
            </td>
            <td>
                <asp:TextBox ID="txtShortDescription" runat="server" MaxLength="500" TextMode="MultiLine"
                    CssClass="textnew" Style="height: 50px;"></asp:TextBox>
            </td>
            <td>
                <asp:Literal ID="Literal4" Text="<%$Resources:Swedish,Picture %>" runat="server">
                </asp:Literal>
            </td>
            <td>
                <asp:FileUpload ID="fuImage" runat="server" />
                <asp:Button ID="btnUpload" runat="server" Text="<%$Resources:Swedish,Upload %>" OnClick="btnUpload_Click"
                    ValidationGroup="UploadPicture" />
                <asp:RegularExpressionValidator ID="regexValidator" runat="server" ControlToValidate="fuImage"
                    ErrorMessage="<%$Resources:Swedish,plzimg %>" ValidationExpression="(.*?)\.(jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF)$"
                    ValidationGroup="UploadPicture">
                </asp:RegularExpressionValidator>
                <br />
                <span class="HelpText">
                    <asp:Literal ID="Literal9" Text="<%$Resources:Swedish,imgdply %>" runat="server">
                    </asp:Literal></span>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Literal ID="Literal11" Text="<%$Resources:Swedish,Language %>" runat="server">
                </asp:Literal>
            </td>
            <td>
                <asp:DropDownList ID="drpLanguage" runat="server" AutoPostBack="true" OnSelectedIndexChanged="drpLanguage_SelectedIndexChanged">
                </asp:DropDownList>
            </td>
            <td>
                <asp:Literal ID="Literal5" Text="<%$Resources:Swedish,ShowReferenceLink %>" runat="server">
                </asp:Literal>
            </td>
            <td>
                <asp:CheckBox ID="chkShowReferenceLink" runat="server" />
            </td>
        </tr>
        <tr>
            <td>
                <asp:Literal ID="Literal6" Text="<%$Resources:Swedish,Reporter %>" runat="server">
                </asp:Literal>
            </td>
            <td>
                <asp:TextBox ID="txtReporter" runat="server" MaxLength="50" CssClass="textnew"></asp:TextBox>
            </td>
            <td>
                <asp:Literal ID="Literal7" Text="<%$Resources:Swedish,ShowReporter %>" runat="server">
                </asp:Literal>
            </td>
            <td>
                <asp:CheckBox ID="chkShowReporter" runat="server" />
            </td>
        </tr>
        <tr>
            <td valign="top" colspan="4">
                <asp:Literal ID="Literal8" Text="<%$Resources:Swedish,Description %>" runat="server">
                </asp:Literal>
                <br />
                <br />
                <%--<asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" CssClass="textnew_multi" style="display:none"></asp:TextBox>--%>
                <CKEditor:CKEditorControl ID="txtDescription" runat="server" BaseHref="~/ckeditor"
                    Height="200px" Width="950px"></CKEditor:CKEditorControl>
            </td>
        </tr>
        <tr id="trPicture" runat="server">
            <td valign="top" colspan="4">
                <div style="height: 370px; overflow: scroll">
                    <asp:DataList ID="dlPictures" runat="server" RepeatColumns="5" RepeatDirection="Horizontal"
                        OnItemCommand="dlPictures_ItemCommand" Width="900px">
                        <ItemTemplate>
                            <div class="divgallery">
                                <img src='<%#Page.ResolveUrl(Eval("Path").ToString()) %>' alt="" height="150" width="165" />
                                <center>
                                    <asp:ImageButton ID="btnDelete" runat="server" ImageUrl="~/App_Themes/default/images/delete_ico.png"
                                        OnClientClick="return confirm('Are you sure wants to delete?')" CommandArgument='<%#Eval("ImageID") %>'
                                        CommandName="Remove" />
                                </center>
                            </div>
                        </ItemTemplate>
                    </asp:DataList>
                </div>
                <%--<a style="font-size: larger" href="javascript:$('#<%=FileUpload1.ClientID%>').fileUploadStart()">
                    Start Upload</a>&nbsp; |&nbsp;<a style="font-size: larger" href="javascript:$('#<%=FileUpload1.ClientID%>').fileUploadClearQueue()"><b>Clear</b>
                    </a>--%>
            </td>
        </tr>
        <tr>
            <td colspan="4" align="right" style="padding-right: 10px">
                <asp:Button ID="btnSave" runat="server" Text="<%$Resources:Swedish,Save %>" OnClick="btnSave_Click"
                    ValidationGroup="ManageNews" />
                <asp:Button ID="btnCancel" runat="server" Text="<%$Resources:Swedish,Cancel %>" CausesValidation="false"
                    OnClientClick="return HideEditForm()" />
            </td>
        </tr>
    </table>
</div>
<%--    </ContentTemplate>
</asp:UpdatePanel>--%>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kblau
kblau

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jazzIIIlove

ASKER

Clean approach, swift expert