Need help on UserControl in a Placeholder

Results 1 to 2 of 2

Thread: Need help on UserControl in a Placeholder

  1. #1
    Join Date
    Dec 1969

    Default Need help on UserControl in a Placeholder

    Hi! I need help on making this module work. It is pretty simple actually but I cant make it work. I have an XML file that contains information about a city that gets displayed depending on which city is selected from the dropdown list. Everything works perfectly. But when I placed it inside a Placeholder, it doesnt work anymore. It triggers the event but the Selected Item remains unchanged. I tried using findcontrol but i cant make it work, the ddl value still remains unchanged. I just started working on .NET so would appreciate any help. Below is a snippet of what im working on. Thanks!!! <BR>--------------------------------------------------------------- <BR><BR>aspx file: <BR><BR>&#060;script language="VB" runat="server"&#062; <BR>sub Page_Load <BR>Dim UIModule As Control = Page.LoadControl("location.ascx") <BR>RightUIModules.Controls.Add(UIModule) <BR>end sub <BR>&#060;/script&#062; <BR><BR>&#060;form runat="server"&#062; <BR>&#060;asp:PlaceHolder id="RightUIModules" runat=server/&#062; <BR>&#060;/form&#062; <BR><BR>--------------------------------------------------------------- <BR>ascx file: <BR><BR>&#060;%@ Control Language="VB" Inherits="Location" Src="location.vb" %&#062; <BR><BR>&#060;P style="font: 8pt verdana;padding:2,2,2,2"&#062; <BR><BR> <BR>Location: <BR><BR>&#060;asp:DropDownList AutoPostBack="True" cssclass="NormalButton" id="city" runat="server"&#062; <BR>&#060;asp:ListItem Value="Morgan Hill" Selected="True"&#062;Houston, TX&#060;/asp:ListItem&#062; <BR>&#060;asp:ListItem Value="Richardson"&#062;San Francisco, CA&#060;/asp:ListItem&#062; <BR>&#060;asp:ListItem Value="Plano"&#062;Phoenix, AZ&#060;/asp:ListItem&#062; <BR>&#060;/asp:DropDownList&#062; <BR>&#060;/P&#062; <BR>&#060;asp:Literal id="Literal1" runat="server" /&#062; <BR><BR> <BR>--------------------------------------------------------------- <BR><BR>vb file: <BR><BR>Imports System <BR>Imports System.IO <BR>Imports System.Xml <BR>Imports System.Xml.Xsl <BR>Imports System.Xml.XPath <BR>Imports System.Web <BR>Imports System.Web.UI <BR>Imports System.Web.UI.WebControls <BR>Imports System.Web.UI.HtmlControls <BR>Imports Microsoft.VisualBasic <BR><BR>Public Class Location : Inherits UserControl <BR><BR>Public literal1 as Literal <BR>Public sResult as StringWriter <BR>Public city as DropDownList <BR><BR>Public Sub Page_Load(sender as Object, e as EventArgs) <BR><BR>Dim xmlPath as String = Server.MapPath("city.xml") <BR>Dim xmlString as String <BR><BR>Dim xslPath as String = Server.MapPath("city.xslt") <BR>dim fs as FileStream = new FileStream(xmlPath, FileMode.Open, FileAccess.Read) <BR>Dim reader as StreamReader = new StreamReader(fs) <BR>Dim XmlReader as XmlTextreader = new XmlTextReader(reader) <BR><BR>Dim doc as XPathDocument = new XPathDocument(xmlReader) <BR><BR>Dim args as XsltArgumentList = new XsltArgumentList() <BR>args.AddParam("citylocn","",city.Selecteditem. Value) <BR><BR>Dim XslDoc as XslTransform = new XslTransform() <BR><BR>XslDoc.Load(xslPath) <BR><BR>dim oStrW as new StringWriter() <BR>XslDoc.Transform(doc,args,oStrw) <BR>Literal1.Text = oStrw.ToString <BR><BR>oStrw.Close() <BR><BR>reader.close() <BR>XmlReader.Close() <BR><BR>End Sub <BR><BR>End Class <BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default Move your Page_Load code to Page_Init

    I&#039;m not 100% sure that will work, but I have run across issues with autopostbacks and generated controls when I build them in Page_Load.<BR><BR>Give it a shot and let us know if it works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts