473,624 Members | 2,223 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.QuerySt ring 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.QuerySt ring so

Request.QuerySt ring["dbid"],Request.QueryS tring["reportid"]

but what I want to so is to generate dynamic HTML based upon the values
of the Request.QuerySt ring 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="Cust om" Namespace="Repo rtUIClassLibrar y"
Assembly = "ReportUIClassL ibrary" %>
<%@ Page language="c#" Codebehind="Dyn amicTest.aspx.c s"
AutoEventWireup ="false" Inherits="Repor tUI.DynamicTest " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>DynamicT est</title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<Custom:WebCust omControl1 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.QuerySt ring 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.W ebControls;
using System.Componen tModel;

namespace ReportUIClassLi brary
{
/// <summary>
/// Summary description for CustomControls.
/// </summary>
[DefaultProperty ("Text"),
ToolboxData("<{ 0}:WebCustomCon trol1
runat=server></{0}:WebCustomCo ntrol1>")]
public class WebCustomContro l1 : System.Web.UI.W ebControls.WebC ontrol
{
private string text;

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

protected override void Render(HtmlText Writer output)
{
Text = ReportUIClassLi brary.BizObject s.GeneratePromp ts("1","3");
output.Write(Te xt);
}
}

}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
3 10829
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(HtmlText Writer output)
{
string myhtml = ReportUIClassLi brary.BizObject s.GeneratePromp ts(Text,
MoreText);
output.Write(my html);
}
Then in your webpage's codebehind:

WC1.Text = Request.QuerySt ring["dbid"];
WC1.MoreText = Request.QuerySt ring["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********@net scape.net> wrote in message
news:OE******** *****@tk2msftng p13.phx.gbl...
Does anyone know if its possible to pass parameters or the values of
Request.QuerySt ring 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.QuerySt ring so

Request.QuerySt ring["dbid"],Request.QueryS tring["reportid"]

but what I want to so is to generate dynamic HTML based upon the values
of the Request.QuerySt ring 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="Cust om" Namespace="Repo rtUIClassLibrar y"
Assembly = "ReportUIClassL ibrary" %>
<%@ Page language="c#" Codebehind="Dyn amicTest.aspx.c s"
AutoEventWireup ="false" Inherits="Repor tUI.DynamicTest " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>DynamicT est</title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<Custom:WebCust omControl1 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.QuerySt ring 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.W ebControls;
using System.Componen tModel;

namespace ReportUIClassLi brary
{
/// <summary>
/// Summary description for CustomControls.
/// </summary>
[DefaultProperty ("Text"),
ToolboxData("<{ 0}:WebCustomCon trol1
runat=server></{0}:WebCustomCo ntrol1>")]
public class WebCustomContro l1 : System.Web.UI.W ebControls.WebC ontrol
{
private string text;

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

protected override void Render(HtmlText Writer output)
{
Text = ReportUIClassLi brary.BizObject s.GeneratePromp ts("1","3");
output.Write(Te xt);
}
}

}

*** 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(HtmlText Writer output)
{
string myhtml = ReportUIClassLi brary.BizObject s.GeneratePromp ts(Text,
MoreText);
output.Write(my html);
}

caused a 'System.StackOv erflowException ' 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********@net scape.net> wrote in message
news:%2******** **********@TK2M SFTNGP11.phx.gb l...
Thanks for the information James,
I tried what you suggested but having Render as

protected override void Render(HtmlText Writer output)
{
string myhtml = ReportUIClassLi brary.BizObject s.GeneratePromp ts(Text,
MoreText);
output.Write(my html);
}

caused a 'System.StackOv erflowException ' 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
4741
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 and is defined in an assembly common to the client and server components. The custom class merely defines three (3) constructors -- the null constructor; one with a string parameter; and one with a string and innner exception parameter -- that...
3
1758
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 that I've got this control, which contains some input fields and some pictures, I use this control in an aspx page with a form around it. When I post the form to a payment page, asp.net turns it from to _. I only want it to pass . Is there any...
2
46393
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 at .ascx? Thank you for your help!
0
1900
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 control. In a default.aspx page <SkinExample:Hello id="HelloControl" SkinName="red" runat="server" /> i can pass the value, it works fine, but from the dropdownlist in a codebehind page i can't pass the value. Could some one help me out with...
4
7153
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" OR... the only way to do it is to use the QueryString or Session object?
3
3320
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. My main page can be called on to load any of the pages referenced in my table. Therefore, I have no @Register controls in my aspx file. What I do have is this dim myUC as control = Page.LoadControl("~/reqforms/" & GetReqForm(requestID))
7
2512
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 paths to graphics depending on the page the user gets redirected to the loginpage. I found no way to achieve this, since the redirection seems to happen in the background automatically if i set authentication mode to forms. Any ideas are...
4
2752
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 to a stored procedure on the details2.aspx page. I can successfully pass the values from the listbox control to a
4
3833
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. My client-side JavaScript function takes 4 parameters (which are expected to be integers). The idea of passing a single parameter and parsing it on the client has occurred to me, but since I am sure I am not the only person who has situations that...
0
8174
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8624
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7164
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2607
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 we have to send another system
1
1786
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.