Adding parameter to the url from a UserControl

  • Thread starter Thread starter Kjell Arne
  • Start date Start date
K

Kjell Arne

Hi,

How do one add parameters to a URL from a UserControl?

My problem is that I want to set a unique value to the webpage when the
page loads. This value I will use as a identifier for that session
(user). I'm certain it's a simple solution for this. But I have not been
able to locate it yet.

Usually in the old days, I would just generate input hidden tags in the
form tag to hold this data...

I would appreciate greatly for any pointers on this issue.

- Kjell Arne
 
Hi,

I really do not understand what you are trying to do, but anyway this is
what you can do.
You can declare a "hidden" control in several ways, if you are going to use
it only in the server side then any ASP.NET control with the Visible
property to false will not show in the page and it will accesible in the
server side.
if you are planning in using it in the client as well then you can use the
HtmlInputHidden control in the same way that you use other control.

Now a tip that I do not why is not more know, you can declare ANY control in
the HTML as accessable from the server side, all you have to do is put in
the tag runat="server" and then in the page you can declare that control as
of type HtmlGenericControl . One example, let's say that you want to set the
page's title dinamically, this is what you do:
in the HTML page instead of:
<title>listrecords</title>
you use:
<title runat="server" id="pagetag">listrecords</title>

then in the code behind you declare the control as:
protected System.Web.UI.HtmlControls.HtmlGenericControl pagetag;

and set it like :
pagetag.InnerText = "Set from code";


Hope this help,
 
Hi.

Well, my problem is that I am working on a webpage where I do not have
access to anything but my own UserControl project.

When the webpage loads, I want to write a unique identifier string that
will be placed somewhere(?!) in the webpage, so I can retrieve it when
the user sends post data to the server. That way I can register that id
in the database and make sure that he does not register again with that
session key.

I've been told that I might be able to add parametres to the url in the
browser?! (I cannot see how that is possible though, but I'm new to C# so..)


- Kjell Arne
 
Hi again,

So in other words you are programming the control and you do not control
when/where this control will be used, right?
If that is so, then I think that you do not need to put a string in the page
you can generate this id when the cnotrol is build the first time, then it
will be kept using the state. you can make this property public if you need
so.


Hope this help,
 
Hi..

And thanks you for your help. Do you think you can give me an example of
doing this? I do not understand what you mean with "You can generate
this id and it will be kept using the state".

So how do I generate this id? And what is a state? Are you refering to
VIEWSTATE?

- Kjell Arne
 
Back
Top