Retrieving JavaScript value from code behind

N

niju

Hi there
I wired up the Javascript function "Business" OnPreRender Event

protected override void OnPreRender(EventArgs e)
{
optBussiness.Attributes.Add("OnClick", "Business();")
}


Here is the javascript
----------------------


function loadIntoElement (id, text)
{
if (document.getElementById)
{
var el = document.getElementById(id);
while (el.hasChildNodes())
el.removeChild(el.lastChild);
el.innerHTML = text;
}


}


function Business()
{
loadIntoElement('BusinessName'­, 'Business Name: <input id
="txtBusinessName"
name="txtBusinessName" value="<%= BusinessName %>" size="20"
maxlength=20 value="" class="textbox">');


How can I retrieve the value of "txtBusinessName" from code behind
file?

Many Thanks
Niju
 
N

niju

Hi John
This is what i did in the code behind
declare the variable

protected System.Web.UI.HtmlControls.HtmlInputText txtBusinessName;


Retrive the value of txtBusinessName

string strBusinessName = txtBusinessName.Value;


But i get exception.

Many Thanks
Niju
 
K

Kevin Spencer

It looks to me like you're going to a lot of trouble and complication to do
something fairly simple. However, I'm not sure what it is on the client that
you're trying to do (you didn't say what, only how, and the how is kind of
funky). Can you tell us what exactly you're trying to accomplish
(requirement)?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Paranoia is just a state of mind.

Hi there
I wired up the Javascript function "Business" OnPreRender Event

protected override void OnPreRender(EventArgs e)
{
optBussiness.Attributes.Add("OnClick", "Business();")
}


Here is the javascript
----------------------


function loadIntoElement (id, text)
{
if (document.getElementById)
{
var el = document.getElementById(id);
while (el.hasChildNodes())
el.removeChild(el.lastChild);
el.innerHTML = text;
}


}


function Business()
{
loadIntoElement('BusinessName'­, 'Business Name: <input id
="txtBusinessName"
name="txtBusinessName" value="<%= BusinessName %>" size="20"
maxlength=20 value="" class="textbox">');


How can I retrieve the value of "txtBusinessName" from code behind
file?

Many Thanks
Niju
 
J

John Rivers

Hello,

I think you need to read up on HTTP and HTML.

That way you will see how these ASP.NET abstractions map to what
is really happening.

The value will be in

Request.QueryString["txtBusinessName"]
or
Request.Form["txtBusinessName"]

John
 
D

DotNet Developer

John said:
Hello,

I think you need to read up on HTTP and HTML.

That way you will see how these ASP.NET abstractions map to what
is really happening.

The value will be in

Request.QueryString["txtBusinessName"]
or
Request.Form["txtBusinessName"]

John
Hi John
This is what i did in the code behind
declare the variable

protected System.Web.UI.HtmlControls.HtmlInputText txtBusinessName;


Retrive the value of txtBusinessName

string strBusinessName = txtBusinessName.Value;


But i get exception.

Many Thanks
Niju

John is right, you need to take it from Request.Form["txtBusinessName"].
You do not need to define as http control and you should not, this may
create a confusion.

--


(e-mail address removed)
http://www.freelancedotnetdeveloper.com
Providing consultancy services in .NET
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,265
Messages
2,571,069
Members
48,771
Latest member
ElysaD

Latest Threads

Top