472,353 Members | 1,184 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Passing parameters from a Web page to a custom control

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 dbid and Parameter # 2 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 this is 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);
}
}

}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
3 10634
First of all, you should not be setting Text in Render(). (It should
not change any property)

Render really wants to be something like:

protected override void Render(HtmlTextWriter output)
{
string myhtml = ReportUIClassLibrary.BizObjects.GeneratePrompts(Te xt,
MoreText);
output.Write(myhtml);
}
Then in your webpage's codebehind:

WC1.Text = Request.QueryString["dbid"];
WC1.MoreText = Request.QueryString["reportid"];

Actually, you'll probably want to create properties called DbId & ReportId
instead of Text & MoreText

--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)
"Joe Bloggs" <bo********@netscape.net> wrote in message
news:OE*************@tk2msftngp13.phx.gbl...
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 dbid and Parameter # 2 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 this is 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);
}
}

}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
Thanks for the information James,
I tried what you suggested but having Render as

protected override void Render(HtmlTextWriter output)
{
string myhtml = ReportUIClassLibrary.BizObjects.GeneratePrompts(Te xt,
MoreText);
output.Write(myhtml);
}

caused a 'System.StackOverflowException' exception in the
DefaultDomain. It's definitely this code that is causing the exception.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Something in either GeneratePrompts & or the property getters is
triggering Render, so it's just calling itself recursively until the stack
overflows.

--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)
"Joe Bloggs" <bo********@netscape.net> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
Thanks for the information James,
I tried what you suggested but having Render as

protected override void Render(HtmlTextWriter output)
{
string myhtml = ReportUIClassLibrary.BizObjects.GeneratePrompts(Te xt,
MoreText);
output.Write(myhtml);
}

caused a 'System.StackOverflowException' exception in the
DefaultDomain. It's definitely this code that is causing the exception.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Ken Allen | last post by:
I have a .net client/server application using remoting, and I cannot get the custom exception class to pass from the server to the client. The...
3
by: Miroslav Ostojic | last post by:
Hallo people... I desperatly need help with one problem... I've got this .net web application that I need to pass some parameters from, to a...
2
by: Akira | last post by:
Hello. I'm having problem with passing parameters from .aspx file to user control. Could anyone tell me how to pass parameters from .aspx file to...
0
by: adam | last post by:
i have custom user control and i'm trying to pass values to custom user control......I need help it seems to me i cannot pass the value to user...
4
by: David Freeman | last post by:
Hi There! I'm just wondering if there's a way to pass parameters (as if you were passing parameters to a ASCX web control) when calling an ASPX...
3
by: voro.cibus | last post by:
I have been reading up on this all day, and I can't find the answer (or more likely, don't understand the answers I have found) to my problem. I...
7
by: Trollpower | last post by:
Hello NG, i need to know how i can pass parameters to the loginpage if i use authentication mode Forms. I need to pass different paramaters, such...
4
by: Ranginald | last post by:
Hi, I'm having trouble passing a parameter from my default.aspx page to my default2.aspx page. I have values from a query in a list box and...
4
by: Nathan Sokalski | last post by:
I am a beginner with AJAX, and have managed to learn how to use it when passing single parameters, but I want to return more than one value to the...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.