usercontrol中的usercontrol [英] Usercontrol within a usercontrol

查看:111
本文介绍了usercontrol中的usercontrol的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:当用户在textarea(UserControl2)中写入一些文本时,当他试图点击Radiobutton中的任何一个(来自UserControl1)时,页面将被回发并且textarea的文本值将丢失。我还为textarea启用了viewstate。



请指导我。当用户点击单选按钮时,如何保存textarea的值。





Issue : When the user is writing some text in the textarea(UserControl2) and in between when he tries to click anyone of the Radiobutton(from UserControl1) the page is posted back and the text value of the textarea is lost. I have also enable viewstate for the textarea.

Please guide me. How can I save the value of the textarea when the user clicks a radio button.


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="PictureUploader.ascx.cs"

    Inherits="Controls_PictureUploader" EnableViewState="true" %>


    <div style="overflow:auto; height:900px;width:1000px;">
<table width="100%">
    <tr>
        <td>
            <asp:DataList ID="DataList1" runat="server" CellPadding="10" Width="1000px" RepeatColumns="7" RepeatDirection="Horizontal" BorderColor="black"

                BorderStyle="Solid" BorderWidth="1px" BackColor="LightSkyBlue" OnItemCommand="DataList1_ItemCommand">
                <ItemTemplate>
                    <table width="100%" border="0">
                        <tr>
                            <td>
                                <img id="Image1" title="Thumbnail"  runat="server" alt="No Image" style="width:100px;height:90px"

                                src='<%# DataBinder.Eval(Container.DataItem, "imagepath") %>' />
                            </td>
                        </tr>
                        <tr>
                            <td>
                               <asp:Label ID="lblImgName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "imageid") %>' ForeColor="white"></asp:Label>
                               <asp:LinkButton ID="LinkButton1" runat="server" CommandName ="Delete" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "imageid") %>'>Delete</asp:LinkButton>
                               
                            </td>
                        </tr>
                    </table>
                    
                </ItemTemplate>
            </asp:DataList>
            
            <asp:RadioButtonList runat="server" RepeatColumns="7" Width="100%" ID="GalleryCheck" DataTextField="imageid" DataTextFormatString="Gallery-{0}" DataValueField="imageid"

                 RepeatDirection="Horizontal" OnSelectedIndexChanged="GalleryCheck_SelectedIndexChanged" EnableViewState="true" AutoPostBack="true" OnDataBinding="GalleryCheck_DataBinding">
                 </asp:RadioButtonList>
        </td>
    </tr>
   
    <tr>
        <td>
           <asp:Button ID="Button1" Text="Done" runat="server" OnClick="btnUpload_Click"/>
            <div style = "padding:20px">
                <asp:FileUpload ID="FileUpload1" runat="server" />
            </div>
        </td>
    </tr>
</table>
</div>

<script type = "text/javascript">


$(document).ready(function () {
        $("#<%=FileUpload1.ClientID%>").uploadify({
        'swf': '../uploadie/uploadify.swf',
        'cancelImg': '../uploadify/cancel.png',
        'buttonText': 'Browse Files',
        'uploader': '../Upload.ashx',
        'folder': 'UploadImages',
        'fileTypeDesc': 'Images',
        'fileTypeExts': '*.jpg;*.jpeg;*.gif;*.png',
        'multi': true,
        'auto': true,
        'simUploadLimit': 10,
        'queueSizeLimit': 1024

    });
   }
);
</script>










protected void GalleryCheck_SelectedIndexChanged(object sender, EventArgs e)
        {
            string sqlcommand = "update auctionimages set GalleryPic = 1 where imageid =" + GalleryCheck.SelectedValue + "; update auctionimages set GalleryPic = 0 where imageid <>" + GalleryCheck.SelectedValue + " and auctionid = " + Session["localauctionid"].ToString();
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand cmd = db.GetSqlStringCommand(sqlcommand);
            db.ExecuteNonQuery(cmd);
            LoadImages();
        }

        protected void GalleryCheck_DataBinding(object sender, EventArgs e)
        {
            RadioButtonList objRdList = (RadioButtonList)sender;
            DataSet objDs = (DataSet)objRdList.DataSource;

            if (objDs.Tables[0].Rows.Count > 0)
            {
                    DataRow[] oDrArray = objDs.Tables[0].Select("GalleryPic = 1");
                if (oDrArray.Length > 0)
                {
                    objRdList.SelectedValue = oDrArray[0]["imageid"].ToString();
                }
            }
        }










<%@ Control Language="VB" AutoEventWireup="true" CodeFile="AddAuctionStep3b.ascx.vb" Inherits="Controls_AddAuctionStep3b" EnableViewState="true" %>
<%@ Register Src="../Controls/PictureUploader.ascx" TagName="PictureUploader" TagPrefix="uc1" %>
<script language="JavaScript" type="text/javascript" src="../wysiwyg.js"></script>

 <link href="../uploadie/uploadify.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../uploadie/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../uploadie/jquery.uploadify.js"></script>
<script type="text/javascript" src="../uploadie/swfobject.js"></script>

<script language="javascript" type="text/javascript">

function fnShowPreview(vInvId)
{
   // testwindow=window.open("../pages/PreviewHtml.aspx?listid=" + vInvId, "mywindow", "location=1,status=1,scrollbars=1,width=600,height=500,resizable=yes,menubar=no,directories=no;", false);
    //testwindow.moveTo(0,0);
   
}
function Confirmation()
{
    if(confirm('Template has changed, Do you want to reload?'))
    {return true;}
    else
    {return false;}
}

</script>
<div id="content">
		<!--  ADD PICTURES  -->

        <fieldset>
            <table>
                <tr>
                    <td>
                        Customer:
                    </td>
                    <td>
                        <asp:Label runat="server" ID="LblCustomer"></asp:Label>   
                    </td>
                    <td>
                        Location ID:
                    </td>
                    <td>
                        <asp:Label runat="server" ID="LblLocationId"></asp:Label>   
                    </td>
                    <td>
                        Inv. Id:
                    </td>
                    <td>
                        <asp:Label runat="server" ID="LblListingId"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        Listing Title:
                    </td>
                    <td>
                        <asp:Label runat="server" ID="LblInvTitle"></asp:Label>
                    </td>
                    <td>
                        Status:
                    </td>
                    <td align="left">
                        <asp:Label runat="server" ID="LblStatus"></asp:Label>   
                    </td>
                    <td>
                        Ebay Item#:
                    </td>
                    <td>
                        <asp:Label runat="server" ID="LblItemNo"></asp:Label>   
                    </td>
                </tr>
            
            </table>
        
        </fieldset>
        <fieldset>
    <legend>Listing Description and Images</legend>
        <br />
        </fieldset>
            <legend>Thumbnail Images</legend>
            <table width="100%" border="0" >
                <tr>
                    <td colspan="2">
                        <uc1:PictureUploader id="PictureUploader1"  runat="server" EnableViewState="true">
                        </uc1:PictureUploader>
                    </td>
                </tr>
            </table>
        
                 
        <fieldset>
            <legend>Listing Description</legend>
            <table width="100%" border="0">
                <tr>
                    <td>
                    <asp:Label ID="Label1" Text="Load" runat="server"></asp:Label>      
                     <asp:DropDownList ID="ddTemplates" runat="server" DataSourceID="SqlDataSource1" DataTextField="TemplateName"

                        DataValueField="TemplateId">
                    </asp:DropDownList>
                    <asp:ImageButton ID="ibtnLdTemp" runat="server" ImageUrl="~/Images/LoadBtn.png"

                                CssClass="menuButton" ImageAlign="Top" OnClick="ibtnLdTemp_Click" />
                     <asp:SqlDataSource ID="SqlDataSource1" runat="server"

                        ConnectionString="<%$ ConnectionStrings:TMTConnectionString %>"

                        SelectCommand="SELECT [TemplateId], [TemplateName] FROM [TMT_Templates] WHERE (([ChannelId] = @ChannelId) AND ([UserName] = @sessUsrId) AND ([TemplateStatusId] in (2,3))) ORDER BY [TemplateStatusId] DESC">
                        <SelectParameters>
                        <asp:SessionParameter Name="sessUsrId" SessionField ="ParentUserId" />
                        <asp:SessionParameter Name="ChannelId" SessionField ="ChannelId" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                         
                            <asp:Label ID="Label2" runat="server" Text="Global"></asp:Label>
                            <asp:DropDownList ID="ddlGlobalTemplate" runat="server" DataSourceID="SqlDataSource2"

                                DataTextField="GlobalTemplateName" DataValueField="GlobalTemplateId">
                            </asp:DropDownList>
                            <asp:ImageButton ID="ibtnLoadTemplate" runat="server" ImageUrl="~/Images/LoadBtn.png"

                                CssClass="menuButton" ImageAlign="Top" OnClick="ibtnLoadTemplate_Click" />
                            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TMTConnectionString %>"

                                SelectCommand="SELECT [GlobalTemplateId], [GlobalTemplateName] FROM [TMT_Globaltemplates]">
                            </asp:SqlDataSource>
                                        
                                        
                            <%--<asp:Button runat="server" Text ="  Reload  " id="btnReload" />  --%>
                            <asp:Button ID="btnReload" runat="server" Text=" Reload " OnClientClick="return Confirmation();" OnClick="btnReload_Click" />
                    </td>
                    <td> </td>
                </tr>
                <%--<tr>
                 <td valign="bottom">
                    <br />
                   <asp:DropDownList runat="server" AutoPostBack="true"  ID="ddTemplateType" DataTextField="TemplateName"
                        DataValueField="TemplateId">
                        </asp:DropDownList>
                    <br />
                </td>
                </tr>--%>
                <tr>
                    <td colspan="2">
                       <%-- <asp:RadioButtonList runat="server" AutoPostBack="true" RepeatDirection="Horizontal" ID="RdTemplateType">
                            <asp:ListItem Text="Use Default Template" Selected="true" Value="Default"></asp:ListItem>
                            <asp:ListItem Text="Use Saved Template" Value="CustomizeDefault"></asp:ListItem>
                            <asp:ListItem Text="No Template" Value="NoTemplate"></asp:ListItem>
                        </asp:RadioButtonList>--%>
                    </td>
                </tr>
                
                 <tr>
                <td colspan="2">
                    <table width="100%">
                        <tr>
                            <td>
                            <asp:HiddenField id="hdnListingDesc" runat="server" Value="" />
                                <textarea id="richbox" cols="25" rows="5"  runat="server" enableviewstate="true"></textarea>
                 

                                <script type="text/javascript">
                                    generate_wysiwyg('ctl00_ContentPlaceHolder1_AddAuctionStep3b_1_richbox');
                                </script>

                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
                
                    
            </table>
          </fieldset>

		
	<fieldset>
		<asp:button id="btnSave" runat="server" Text=" Save  " Width="130px"></asp:button>
		<asp:button id="btnContinue" runat="server" Text="Edit Listing" Width="200px"></asp:button>
		<input type="button" id="btnPreview"  value="Preview Template"    önclick="openPopUp();"/>
	</fieldset>
</div>

<script language="javascript" type="text/javascript">
function openPopUp()
{
    var strValue = document.getElementById("ctl00_ContentPlaceHolder1_AddAuctionStep3b_1_richbox").value;
    window.open().document.writeln(strValue)
    return true;
}

function setListDesc()
{
    viewSource("ctl00_ContentPlaceHolder1_AddAuctionStep3b_1_richbox"); //document.getElementById("txtListingDesc").value;
    var strValue = document.getElementById("ctl00_ContentPlaceHolder1_AddAuctionStep3b_1_richbox").value;
    document.getElementById("ctl00_ContentPlaceHolder1_AddAuctionStep3b_1_richbox").value = strValue;
}

function window_onunload()
{
}
</script>










Private Sub SaveDateToDatabase()

        'If Not RdTemplateType.Items(2).Selected Then
        m_Item = CType(Session(WebConstants.Session_Item), ItemType)
        Dim db As Database = DatabaseFactory.CreateDatabase()
        Dim sqlCommand As String = ""

        sqlCommand = "SaveAuctionStep3b"

        Dim cmd As DbCommand = db.GetStoredProcCommand(sqlCommand)

        If (Session("localauctionid") <> Nothing And Session("localauctionid").ToString() <> "") Then
            db.AddInParameter(cmd, "@auctionid", DbType.Int32, Session("localauctionid").ToString())
        Else
            db.AddInParameter(cmd, "@auctionid", DbType.Int32)
        End If

        

        Dim strTxt As String
        strTxt = richbox.InnerHtml.Replace(Request.Url.AbsoluteUri.ToString().Replace("&", "&").Replace("&", "&"), "")

        Dim strTxt2 As String
        strTxt2 = richbox.InnerHtml.Replace(Request.Url.AbsoluteUri.ToString().Replace("&", "&").Replace("&", "&"), "")

        db.AddInParameter(cmd, "@desc", DbType.String, Replace(strTxt2, "'", "''"))

        If (ddTemplates.Items.Count <> 0) Then
            db.AddInParameter(cmd, "@TemplateType", DbType.String, Replace(ddTemplates.SelectedItem.Value, "'", "''"))
        Else
            db.AddInParameter(cmd, "@TemplateType", DbType.String, "NoTemplate")
        End If


        db.ExecuteNonQuery(cmd)
        'End If

    End Sub










Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

      If (checkSession()) Then

          If (String.IsNullOrEmpty(Session("ChannelId"))) Then
              Session("ChannelId") = "1"
          End If
          If Not IsPostBack Then
              If (Request.QueryString("listid") <> "") Then
                  GetDataFromDatabase()
                  LoadTemplates()
                  'getTemplateDetails()
              End If
          End If
      Else
          Response.Redirect("~/Pages/Login.aspx", False)
          Return
      End If

  End Sub

推荐答案

(do cument).ready(function () {
(document).ready(function () {


(\"#<%=FileUpload1.ClientID%>\").uploadify({
'swf': '../uploadie/uploadify.swf',
'cancelImg': '../uploadify/cancel.png',
'buttonText': 'Browse Files',
'uploader': '../Upload.ashx',
'folder': 'UploadImages',
'fileTypeDesc': 'Images',
'fileTypeExts': '*.jpg;*.jpeg;*.gif;*.png',
'multi': true,
'auto': true,
'simUploadLimit': 10,
'queueSizeLimit': 1024

});
}
);
</script>
("#<%=FileUpload1.ClientID%>").uploadify({ 'swf': '../uploadie/uploadify.swf', 'cancelImg': '../uploadify/cancel.png', 'buttonText': 'Browse Files', 'uploader': '../Upload.ashx', 'folder': 'UploadImages', 'fileTypeDesc': 'Images', 'fileTypeExts': '*.jpg;*.jpeg;*.gif;*.png', 'multi': true, 'auto': true, 'simUploadLimit': 10, 'queueSizeLimit': 1024 }); } ); </script>










protected void GalleryCheck_SelectedIndexChanged(object sender, EventArgs e)
        {
            string sqlcommand = "update auctionimages set GalleryPic = 1 where imageid =" + GalleryCheck.SelectedValue + "; update auctionimages set GalleryPic = 0 where imageid <>" + GalleryCheck.SelectedValue + " and auctionid = " + Session["localauctionid"].ToString();
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand cmd = db.GetSqlStringCommand(sqlcommand);
            db.ExecuteNonQuery(cmd);
            LoadImages();
        }

        protected void GalleryCheck_DataBinding(object sender, EventArgs e)
        {
            RadioButtonList objRdList = (RadioButtonList)sender;
            DataSet objDs = (DataSet)objRdList.DataSource;

            if (objDs.Tables[0].Rows.Count > 0)
            {
                    DataRow[] oDrArray = objDs.Tables[0].Select("GalleryPic = 1");
                if (oDrArray.Length > 0)
                {
                    objRdList.SelectedValue = oDrArray[0]["imageid"].ToString();
                }
            }
        }










<%@ Control Language="VB" AutoEventWireup="true" CodeFile="AddAuctionStep3b.ascx.vb" Inherits="Controls_AddAuctionStep3b" EnableViewState="true" %>
<%@ Register Src="../Controls/PictureUploader.ascx" TagName="PictureUploader" TagPrefix="uc1" %>
<script language="JavaScript" type="text/javascript" src="../wysiwyg.js"></script>

 <link href="../uploadie/uploadify.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../uploadie/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../uploadie/jquery.uploadify.js"></script>
<script type="text/javascript" src="../uploadie/swfobject.js"></script>

<script language="javascript" type="text/javascript">

function fnShowPreview(vInvId)
{
   // testwindow=window.open("../pages/PreviewHtml.aspx?listid=" + vInvId, "mywindow", "location=1,status=1,scrollbars=1,width=600,height=500,resizable=yes,menubar=no,directories=no;", false);
    //testwindow.moveTo(0,0);
   
}
function Confirmation()
{
    if(confirm('Template has changed, Do you want to reload?'))
    {return true;}
    else
    {return false;}
}

</script>
<div id="content">
		<!--  ADD PICTURES  -->

        <fieldset>
            <table>
                <tr>
                    <td>
                        Customer:
                    </td>
                    <td>
                        <asp:Label runat="server" ID="LblCustomer"></asp:Label>   
                    </td>
                    <td>
                        Location ID:
                    </td>
                    <td>
                        <asp:Label runat="server" ID="LblLocationId"></asp:Label>   
                    </td>
                    <td>
                        Inv. Id:
                    </td>
                    <td>
                        <asp:Label runat="server" ID="LblListingId"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        Listing Title:
                    </td>
                    <td>
                        <asp:Label runat="server" ID="LblInvTitle"></asp:Label>
                    </td>
                    <td>
                        Status:
                    </td>
                    <td align="left">
                        <asp:Label runat="server" ID="LblStatus"></asp:Label>   
                    </td>
                    <td>
                        Ebay Item#:
                    </td>
                    <td>
                        <asp:Label runat="server" ID="LblItemNo"></asp:Label>   
                    </td>
                </tr>
            
            </table>
        
        </fieldset>
        <fieldset>
    <legend>Listing Description and Images</legend>
        <br />
        </fieldset>
            <legend>Thumbnail Images</legend>
            <table width="100%" border="0" >
                <tr>
                    <td colspan="2">
                        <uc1:PictureUploader id="PictureUploader1"  runat="server" EnableViewState="true">
                        </uc1:PictureUploader>
                    </td>
                </tr>
            </table>
        
                 
        <fieldset>
            <legend>Listing Description</legend>
            <table width="100%" border="0">
                <tr>
                    <td>
                    <asp:Label ID="Label1" Text="Load" runat="server"></asp:Label>      
                     <asp:DropDownList ID="ddTemplates" runat="server" DataSourceID="SqlDataSource1" DataTextField="TemplateName"

                        DataValueField="TemplateId">
                    </asp:DropDownList>
                    <asp:ImageButton ID="ibtnLdTemp" runat="server" ImageUrl="~/Images/LoadBtn.png"

                                CssClass="menuButton" ImageAlign="Top" OnClick="ibtnLdTemp_Click" />
                     <asp:SqlDataSource ID="SqlDataSource1" runat="server"

                        ConnectionString="<%


ConnectionStrings:TMTConnectionString %>\"

SelectCommand=\"SELECT [TemplateId], [TemplateName] FROM [TMT_Templates] WHERE (([ChannelId] = @ChannelId) AND ([UserName] = @sessUsrId) AND ([TemplateStatusId] in (2,3))) ORDER BY [TemplateStatusId] DESC\">
<SelectParameters>
<asp:SessionParameter Name=\"sessUsrId\" SessionField =\"ParentUserId\" />
<asp:SessionParameter Name=\"ChannelId\" SessionField =\"ChannelId\" />
</SelectParameters>
</asp:SqlDataSource>
    
<asp:Label ID=\"Label2\" runat=\"server\" Text=\"Global\"></asp:Label>
<asp:DropDownList ID=\"ddlG lobalTemplate\" runat=\"server\" DataSourceID=\"SqlDataSource2\"

DataTextField=\"GlobalTemplateName\" DataValueField=\"GlobalTemplateId\">
</asp:DropDownList>
<asp:ImageButton ID=\"ibtnLoadTemplate\" runat=\"server\" ImageUrl=\"~/Images/LoadBtn.png\"

< span class =code-attribute> CssClass=\"menuButton\" ImageAlign=\"Top\" OnClick=\"ibtnLoadTemplate_Click\" />
<asp:SqlDataSource ID=\"SqlDataSource2\" runat=\"server\" ConnectionString=\"<%
ConnectionStrings:TMTConnectionString %>" SelectCommand="SELECT [TemplateId], [TemplateName] FROM [TMT_Templates] WHERE (([ChannelId] = @ChannelId) AND ([UserName] = @sessUsrId) AND ([TemplateStatusId] in (2,3))) ORDER BY [TemplateStatusId] DESC"> <SelectParameters> <asp:SessionParameter Name="sessUsrId" SessionField ="ParentUserId" /> <asp:SessionParameter Name="ChannelId" SessionField ="ChannelId" /> </SelectParameters> </asp:SqlDataSource>      <asp:Label ID="Label2" runat="server" Text="Global"></asp:Label> <asp:DropDownList ID="ddlGlobalTemplate" runat="server" DataSourceID="SqlDataSource2" DataTextField="GlobalTemplateName" DataValueField="GlobalTemplateId"> </asp:DropDownList> <asp:ImageButton ID="ibtnLoadTemplate" runat="server" ImageUrl="~/Images/LoadBtn.png" CssClass="menuButton" ImageAlign="Top" OnClick="ibtnLoadTemplate_Click" /> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%


这篇关于usercontrol中的usercontrol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆