Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 29th, 2004, 03:23 PM
Authorized User
 
Join Date: Jun 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default C# passing parameters to custom control class

Does anyone know if its possible to pass parameters or the values of Request.QueryString from a web page to a custom control class? I'm using a C# Web Application. For Example I have Web Page1 which has to parameters passed to it from another Web page

Parameter # 1 name dbid and Parameter # 2 name reportid.

I know that I can access the values of the parameters from the code behind .aspx.cs using Request.QueryString so

Request.QueryString["dbid"],
Request.QueryString["reportid"]

but what I want to so is to generate dynamic HTML based upon the values of the Request.QueryString parameters. I can create a custom control (example below) and hard code in some values for the parameters , call another method and produce the HTML I want but I don't know how to pass the values of the parameters
to the class containing the override version of the Render method. The reason for why I'm trying to pass the parameters is that I have information held in a table that depending on the values of the parameters will then determine the content of the HTML to display.

Can anyone comment on if this is even the right approach or am I going in the worng direction all together.

Here is an example.

Here is my HTML code - note the reference to the custom control via the <Custom> tag.

<%@ Register TagPrefix="Custom" Namespace="ReportUIClassLibrary" Assembly = "ReportUIClassLibrary" %>
<%@ Page language="c#" Codebehind="DynamicTest.aspx.cs" AutoEventWireup="false" Inherits="ReportUI.DynamicTest" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    <HEAD>
        <title>DynamicTest</title>
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
        <Custom:WebCustomControl1 Runat="Server" Text="Test" Id="WC1" />
            <asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 312px; POSITION: absolute; TOP: 104px" runat="server">Label</asp:Label>
        </form>
    </body>
</HTML>

Here is the class containing the code for the custom control and the override of the Render method. Note here I am just calling another method GeneratePrompts that returns a string containing the HTML I want displayed. This method takes two parameters , I want the parameters to be the contents of my Request.QueryString variables, but this is
where I get stuck and I am hard coding in some values just to see if the method call will work.

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace ReportUIClassLibrary
{
    /// <summary>
    /// Summary description for CustomControls.
    /// </summary>
    [DefaultProperty("Text"),
    ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
    public class WebCustomControl1 : System.Web.UI.WebControls.WebControl
    {
        private string text;

        [Bindable(true),
        Category("Appearance"),
        DefaultValue("")]
        public string Text
        {
            get
            {
                return text;
            }
             set
            {
                text = value;
            }
        }

        protected override void Render(HtmlTextWriter output)
        {
            Text = ReportUIClassLibrary.BizObjects.GeneratePrompts("1 ","3");
            output.Write(Text);
        }
    }

}
 
Old October 5th, 2004, 11:44 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Any class that is derived from System.Web.UI.WebControls.WebControl should have full access to the same things that a page does. Have you tried accessing Request.QueryString from within your overrided render method?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Server Control....Custom Property Editor ZArrinPour ASP.NET 1.0 and 1.1 Basics 1 June 15th, 2010 11:30 AM
Web Service, Custom Control, Custom Return Type robzyc ASP.NET 2.0 Basics 6 June 10th, 2008 08:03 AM
custom control inside custom control issues StevesonD ASP.NET 2.0 Professional 1 February 19th, 2008 06:54 PM
passing parameters to user control jbeynon ASP.NET 2.0 Professional 0 August 30th, 2006 06:18 AM
Reference Page Control from Custom Class wirerider ASP.NET 2.0 Professional 6 February 1st, 2006 07:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.