473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

jscript call problem

2
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):
Expand|Select|Wrap|Line Numbers
  1. protected void ActivateScript()
  2.     {
  3. Response.Write("<tr><td> <input type=\"radio\" value=\"1\" name=\"RadioBtn1\" id=\"radiobtn_\" onClick=\"rbChange('TextBox1', true)\"> </td></tr>");
  4. }
On Default.aspx part...I added jscript with function I want to call from aspx.cs file:
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2.     function rbChange(tbId, state){
  3.          var textBox = document.getElementById(tbId);
  4.         tb.disabled = state; 
  5.     }
  6. </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?
Mar 18 '08 #1
4 1652
Frinavale
9,735 Expert Mod 8TB
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):
Expand|Select|Wrap|Line Numbers
  1. protected void ActivateScript()
  2.     {
  3. Response.Write("<tr><td> <input type=\"radio\" value=\"1\" name=\"RadioBtn1\" id=\"radiobtn_\" onClick=\"rbChange('TextBox1', true)\"> </td></tr>");
  4. }
On Default.aspx part...I added jscript with function I want to call from aspx.cs file:
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2.     function rbChange(tbId, state){
  3.          var textBox = document.getElementById(tbId);
  4.         tb.disabled = state; 
  5.     }
  6. </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
Expand|Select|Wrap|Line Numbers
  1. foreach (String radioButtonName in radioButtonNamesList)
  2. {     myRadioButtonList.Items.Add(New ListItem(radioButtonName));}
  3.  
Then you should add the JavaScript call to each of the items in the Radio Button list:
Expand|Select|Wrap|Line Numbers
  1. foreach(ListItem lst in myRadioButtonList.Items)
  2. {    lst.Attributes.Add("onclick","javascript:rbChange('"+TextBox1.ClientID+"',true);");}
  3.  
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
Mar 18 '08 #2
Ajvan
2
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 |
-----------------------------------------------------------------------------
Mar 18 '08 #3
Frinavale
9,735 Expert Mod 8TB
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
Mar 18 '08 #4
Frinavale
9,735 Expert Mod 8TB
You could also create the a table and add it to a Panel:
Expand|Select|Wrap|Line Numbers
  1. Private Sub CreateTable()
  2.   Dim dr As Data.DataRow
  3.   Dim dt As New Data.DataTable 'the table that will hold the card holders
  4. 'add columns to the table so that data can be added to that column
  5.   dt.Columns.Add(New Data.DataColumn("checkbox1", GetType(CheckBox)))
  6.   dt.Columns.Add(New Data.DataColumn("checkbox2", GetType(CheckBox)))
  7.   dt.Columns.Add(New Data.DataColumn("textbox1", GetType(TextBox)))
  8.  
  9. 'do database calls.....then loop through database and create a new row for each record and add the content to the table...
  10.  
  11. For Each s As Object in MyDatabaseResults
  12.     dr= dt.NewRow
  13.     Dim check1 As New CheckBox()
  14.     check1.Attributes.Add("onclick", "javascript:.....")
  15.     check1.Checked = ....
  16.     dr("checkbox1")= check1
  17.     Dim check2 As New CheckBox()
  18.     check2.Attributes.Add("onclick", "javascript:.....")
  19.     check2.Checked = ....
  20.     dr("checkbox2")=check2
  21.     Dim text1 As New TextBox
  22.     text1.Text=....
  23.     dr("TextBox")=text1
  24.     dt.Rows.Add(dr)
  25. Next
  26.  
Expand|Select|Wrap|Line Numbers
  1. myPanel.Controls.Add(myDynamicallyGeneratedTable)
  2.  
Mar 18 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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. ...
6
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,...
5
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...
1
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...
2
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. ...
10
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...
6
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...
7
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...
3
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 :...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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
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
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...

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.