473,513 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10813
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
4732
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 custom exception is derived from ApplicationException...
3
1748
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 payment form page some other place. My problem is...
2
46387
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 user control(.ascx) and how to recieve parameters...
0
1892
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 control from dropdownlist. I have property in a...
4
7150
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 page? e.g. MyDetailsPage.UserName = "david" ...
3
3313
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 have a table that stores the name of my ascx page....
7
2506
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 as a different redirection url, strings and...
4
2747
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 the goal is to pass the "catID" from default.aspx...
4
3820
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 client-side JavaScript function that displays it....
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7160
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7537
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3233
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.