Hi everybody,
I have one problem, and I hope some of you guys can help me with this.
I`m working in C# (Visual Studio 2005)...writing simple web site .
I place grid on Default.aspx and put one textbox in it.
On the other side, on Default.aspx.cs page I write simple method which dynamicly generate Radio Button on page..(code bellow): -
protected void ActivateScript()
-
{
-
Response.Write("<tr><td> <input type=\"radio\" value=\"1\" name=\"RadioBtn1\" id=\"radiobtn_\" onClick=\"rbChange('TextBox1', true)\"> </td></tr>");
-
}
On Default.aspx part...I added jscript with function I want to call from aspx.cs file: -
<script language="javascript" type="text/javascript">
-
function rbChange(tbId, state){
-
var textBox = document.getElementById(tbId);
-
tb.disabled = state;
-
}
-
</script>
Jscript should set the textbox in read only mode when user click on RadioBtn...however..jscript function does not work at all...I don`t know what`s going on..
Of course..from Default.aspx page I call <%ActivateScript();%>
someone have some idea?
4 1652
Hi everybody,
I have one problem, and I hope some of you guys can help me with this.
I`m working in C# (Visual Studio 2005)...writing simple web site .
I place grid on Default.aspx and put one textbox in it.
On the other side, on Default.aspx.cs page I write simple method which dynamicly generate Radio Button on page..(code bellow): -
protected void ActivateScript()
-
{
-
Response.Write("<tr><td> <input type=\"radio\" value=\"1\" name=\"RadioBtn1\" id=\"radiobtn_\" onClick=\"rbChange('TextBox1', true)\"> </td></tr>");
-
}
On Default.aspx part...I added jscript with function I want to call from aspx.cs file: -
<script language="javascript" type="text/javascript">
-
function rbChange(tbId, state){
-
var textBox = document.getElementById(tbId);
-
tb.disabled = state;
-
}
-
</script>
Jscript should set the textbox in read only mode when user click on RadioBtn...however..jscript function does not work at all...I don`t know what`s going on..
Of course..from Default.aspx page I call <%ActivateScript();%>
someone have some idea?
First of all you shouldn't use Response.Write to dynamically generate your Radio Buttons.
Instead you should use a RadioButtonList.
Drag this object on to the page and give it a name....then in your Page_Load function you should dynamically add values to it...
Eg -
foreach (String radioButtonName in radioButtonNamesList)
-
{ myRadioButtonList.Items.Add(New ListItem(radioButtonName));}
-
Then you should add the JavaScript call to each of the items in the Radio Button list: -
foreach(ListItem lst in myRadioButtonList.Items)
-
{ lst.Attributes.Add("onclick","javascript:rbChange('"+TextBox1.ClientID+"',true);");}
-
This will the JavaScript for the "onclick" event to each radio button in the list.
Please note that I'm passing the Textbox1's ClientID. The reason for this is because sometimes your Textbox (control) names are changed to something other than what you code upon rendering....the real ID for the text box is the ClientID.
eg:
You may declare a text box and give it the ID: "MyTextBox" but when it's displayed in the browser the ID could be changed to: "ctl00_MyTextBox" so that .Net is able to tell what textbox belongs to what control if there is more than one control on the page with a textbox named MyTextBox.
-Frinny
first...thanks for your reply...
second...I don`t get it what do you mean with your code...You just tell me not to use Response.Write..but didn`t tell me why not??
Perhaps I should explain problem better:
I read some data from DB. Number of Items on page depends of number of items taken from DB..
so, if I have, let`s say 3 records in DB I have following situation on page:
RadioBtn1 RadioBtn1 (mutually exclusive) TextBox1
RadioBtn2 RadioBtn2 (mutually exclusive) TextBox2
RadioBtn3 RadioBtn3 (mutually exclusive) TextBox3
When user clicks on first RadioBtn (first record) => TextBox goes to Read only
When user clicks on second RadioBtn (first record) => TextBox goes to Read/write
Also, this Items ..as you can see in the first post, should be positioned in Table...
That`s the reason I use Response.Write...perhaps it can be do it in other way, but so far I used this one, and everything works fine...
RadioBtn-s in the same row have same name but different Value, so I can distinct which RadioBtn is checked (RadioBtn definitions in the first post)
-----------------------------------------------------------------------------
| O RadioBtn1 | O RadioBtn1 | TextBox1 |
-----------------------------------------------------------------------------
| O RadioBtn2 | O RadioBtn2 | TextBox2 |
-----------------------------------------------------------------------------
| O RadioBtn3 | O RadioBtn3 | TextBox3 |
-----------------------------------------------------------------------------
first...thanks for your reply...
second...I don`t get it what do you mean with your code...You just tell me not to use Response.Write..but didn`t tell me why not??
Perhaps I should explain problem better:
I read some data from DB. Number of Items on page depends of number of items taken from DB..
so, if I have, let`s say 3 records in DB I have following situation on page:
RadioBtn1 RadioBtn1 (mutually exclusive) TextBox1
RadioBtn2 RadioBtn2 (mutually exclusive) TextBox2
RadioBtn3 RadioBtn3 (mutually exclusive) TextBox3
When user clicks on first RadioBtn (first record) => TextBox goes to Read only
When user clicks on second RadioBtn (first record) => TextBox goes to Read/write
Also, this Items ..as you can see in the first post, should be positioned in Table...
That`s the reason I use Response.Write...perhaps it can be do it in other way, but so far I used this one, and everything works fine...
RadioBtn-s in the same row have same name but different Value, so I can distinct which RadioBtn is checked (RadioBtn definitions in the first post)
-----------------------------------------------------------------------------
| O RadioBtn1 | O RadioBtn1 | TextBox1 |
-----------------------------------------------------------------------------
| O RadioBtn2 | O RadioBtn2 | TextBox2 |
-----------------------------------------------------------------------------
| O RadioBtn3 | O RadioBtn3 | TextBox3 |
-----------------------------------------------------------------------------
The reason you shouldn't use Response.Write is because this will insert your data anywhere in the output stream. This means that your data could be inserted before the <body> tag...even before the <head> or <html> tags. It can appear anywhere and can cause problems.
If I were you, I'd use a Repeater Control to create my table...and adding the JavaScript calls in with the repeater.
-Frinny
You could also create the a table and add it to a Panel: -
Private Sub CreateTable()
-
Dim dr As Data.DataRow
-
Dim dt As New Data.DataTable 'the table that will hold the card holders
-
'add columns to the table so that data can be added to that column
-
dt.Columns.Add(New Data.DataColumn("checkbox1", GetType(CheckBox)))
-
dt.Columns.Add(New Data.DataColumn("checkbox2", GetType(CheckBox)))
-
dt.Columns.Add(New Data.DataColumn("textbox1", GetType(TextBox)))
-
-
'do database calls.....then loop through database and create a new row for each record and add the content to the table...
-
-
For Each s As Object in MyDatabaseResults
-
dr= dt.NewRow
-
Dim check1 As New CheckBox()
-
check1.Attributes.Add("onclick", "javascript:.....")
-
check1.Checked = ....
-
dr("checkbox1")= check1
-
Dim check2 As New CheckBox()
-
check2.Attributes.Add("onclick", "javascript:.....")
-
check2.Checked = ....
-
dr("checkbox2")=check2
-
Dim text1 As New TextBox
-
text1.Text=....
-
dr("TextBox")=text1
-
dt.Rows.Add(dr)
-
Next
-
-
myPanel.Controls.Add(myDynamicallyGeneratedTable)
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Harag |
last post by:
Hi All
I currently thinking of converting from my little knowledge of
VBscript to jScript ASP.
With this in mind I'm looking at my current code to see how it will
convert over to Jscript.
...
|
by: Dan Roberts |
last post by:
I am running some off-the-shelf software that is written in ASP, which uses
JScript to generate dynamic content within HTML forms. There are several ASP
pages which are partially rendering to IE,...
|
by: benc |
last post by:
Hi
Can some good soul help on this. I need to call jscript functions from C#.
I have hosted a web control and displayed an html page successfully, but
just can't find a way to call jscript...
|
by: TdJ |
last post by:
Hi guys,
I am trying to build a dialog box that does the same as an "alert" but with
out the exclamation mark graphic (which is causing some users to think
something has gone wrong !?
I have...
|
by: moondaddy |
last post by:
I'm using vb.net and have an aspx page where I want to call a function in
the code behind to do something on the backend and I want to call this
function from a jscript function in the aspx page. ...
|
by: SergioT |
last post by:
Hi
I wanna to create a jscript function that sets the value of a textbox into a
datagrid, But the problem is How can I obtain the name of the textbox and
send it to my jscript function???? The...
|
by: RFS666 |
last post by:
Hello,
After I posted yesterday "using C# class in jscript", I have a new problem:
I have a C# class - DBResult - that contains (and other variables) a string
array (and other variables), that...
|
by: RFS666 |
last post by:
Hello,
I would like to use variables with a type in jscript.NET.
I declare them as follows:
var x : double = 5.03;
This doesn't work in my script, that I write to the page in codebehind with...
|
by: bowser |
last post by:
Hello,
I have a problem of communication between JScript and C#. I must say
that I'm new to both.
In a JS file I have to call a C# function.
In particular I have:
public function Eval(expr :...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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...
| |