473,385 Members | 1,309 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,385 software developers and data experts.

User control with javascript events and masterpage

6
I have a .ascx file which has a combo box user control - textbox + listbox with a button. when the button is clicked it triggers javascript functions which are registered using registerscript block in vb .net.

The javascript function works fine when master page is not used with hosting page. But when master page is not used it is working fine.

can anybody figured out this problem?
Jul 11 '07 #1
9 6898
kenobewan
4,871 Expert 4TB
Welcome to TSDN. Do you mean that your hosting page JS won't work when you use a master page?
Jul 11 '07 #2
mumbai
6
The javascript function itself is in user control which i register in usercontrol itself. SO the JS is not actually in the hosting page. The JS is injected from the user control after the form tag. Here is the scenario:

1) I have a ascx page
2) hosting page - aspx page - register user control
3) Master page


In user control:
In User controls page load method, Javascript functions are in a string in the user control ( combo box list control - listbox and textbox with an image button that trigeers the JS function ). I register the javascript function using register method . Here is the javascript code in user control (.ascx)


Dim sCID As String = Me.UniqueID & "_"



' Javacsript function
Dim sScript As String = vbCrLf _
& "<script type='text/javascript' language='javascript'>" & vbCrLf _
& "function selectList(sCtrlID, sListID, sTextID) {" & vbCrLf _
& " var list = document.getElementById(sCtrlID + sListID);" & vbCrLf _
& " var text = document.getElementById(sCtrlID + sTextID);" & vbCrLf _
& " text.value = list.options[list.selectedIndex].text;" & vbCrLf _
& " if (sListID == 'listbox') openList(sCtrlID);" & vbCrLf _
& "}" & vbCrLf _
& vbCrLf _
& "function openList(sCtrlID) {" & vbCrLf _
& " var list = document.getElementById(sCtrlID + 'dropbox');" & vbCrLf _
& " var btnimg = document.getElementById(sCtrlID + 'dropbtn');" & vbCrLf _
& " if(list.style.display == 'none') { list.style.display = 'block';" & vbCrLf _
& " btnimg.src = document.getElementById(sCtrlID + 'imageup').src;" & vbCrLf _
& " } else {" & vbCrLf _
& " list.style.display = 'none';" & vbCrLf _
& " btnimg.src = document.getElementById(sCtrlID + 'imagedown').src;" & vbCrLf _
& " }" & vbCrLf _
& " return false;" & vbCrLf _
& "}" & vbCrLf _
& "function scrollList(sCtrlID, sListID, sTextID) {" & vbCrLf _
& " var list = document.getElementById(sCtrlID + sListID);" & vbCrLf _
& " var text = document.getElementById(sCtrlID + sTextID);" & vbCrLf _
& " var search = new String(text.value).toLowerCase();" & vbCrLf _
& " list.selectedIndex = -1;" & vbCrLf _
& " var items = list.options;" & vbCrLf _
& " var option = new String();" & vbCrLf _
& " for (i = 0; i < items.length; i++) {" & vbCrLf _
& " option = items[i].text.toLowerCase();" & vbCrLf _
& " if (option.substring(0, search.length) == search ) {" & vbCrLf _
& " list.selectedIndex = i;" & vbCrLf _
& "break;" & vbCrLf _
& "}" & vbCrLf _
& "}" & vbCrLf _
& "}" & vbCrLf _
& "<" & "/script>" & vbCrLf


-- registering the JS

If Not Page.ClientScript.IsClientScriptBlockRegistered("A HHComboBox") Then
Page.ClientScript.RegisterClientScriptBlock(me.Get Type, "AHHComboBox", sScript)

End If



-- adding js events - listbox(id = dropbox) and textbox (id=textbox2)
-- This does not get triggered when master page is used with Hosting page but without master page it does.

dropbox.Attributes.Add("onclick", "selectList('" & sCID _
& "', 'dropbox', 'textbox2')")
textbox2.Attributes.Add("onkeyup", "scrollList('" & sCID _
& "', 'dropbox', 'textbox2')")
dropbtn.Attributes.Add("onclick", "return openList('" _
& sCID & "')")
Jul 12 '07 #3
rsdev
149 100+
I have a similar problem with dynamically embedding a SWFobject.js into a user control. I also have a master page and when I use Page.RegisterClientScriptBlock(... I get an IE error 'null' is null or not a null object.

Do you also get this error in IE?
Jul 14 '07 #4
mumbai
6
I have a similar problem with dynamically embedding a SWFobject.js into a user control. I also have a master page and when I use Page.RegisterClientScriptBlock(... I get an IE error 'null' is null or not a null object.

Do you also get this error in IE?
Actually i do not get any errors. It does a postback to the asp .net code and event does not occur.
Jul 16 '07 #5
rsdev
149 100+
I managed to fix my problem which wasn't related to the Master page. So I now have a scriptblock of dynamic javascript which works when called by the window.onload method.

In the postback how are you making calls to the javascript?
Jul 17 '07 #6
rsdev
149 100+
Sorry I just noticed that you have onclick etc.

If you have an aspx page with a user control, that inherits a master page this should work fine.

I'd double check that the inherits are set up properly.
Jul 17 '07 #7
mumbai
6
I think it is related to the unique id that i pass. what should be the id sent from the combo box control to the javascript function,
Jul 30 '07 #8
rsdev
149 100+
I code in C# so VB isn't my strong point. You say it's working without the Masterpage so perhaps the problem is the Me indentifier before UniqueID.

In C# with a master page this would become this.Page. So maybe Me.Page is the VB equivalant?

Let me know:)
Jul 31 '07 #9
mumbai
6
I code in C# so VB isn't my strong point. You say it's working without the Masterpage so perhaps the problem is the Me indentifier before UniqueID.

In C# with a master page this would become this.Page. So maybe Me.Page is the VB equivalant?

Let me know:)

I had used Me.unique id in the combo box control and it was not working.
Aug 8 '07 #10

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

Similar topics

2
by: Ahmed | last post by:
Is it possible for a user control on a webform to access the base class(another webfrom) of the host page ? e.g my code does something like this: ChildPage inherits from ParentPage and a...
5
by: Federico | last post by:
I have a problem, I have an event declared in a Master Page, and I want to use in a Content Page holder of a Content Page. When I want to create the method to handle the event, I can njot reference...
2
by: Scott | last post by:
I'm using a master page (mp_TableMaint.aspx) with one Content area (ID: Content1). Content1 contains several usercontrols, which are hidden. The goal is to show the correct control based on the...
1
by: rh | last post by:
Hi, My MasterPage contains a user control used for navigation. I have some .aspx pages that use this MasterPage and I would like to cache only the user control used for navigation. How do I...
13
by: Michael | last post by:
I have setup a public variable in the Master Page "code-behind-file". Now I would like to set that value from the UserControl, but I can't seem to find a way to do this. Does anyone have any ideas?...
0
by: jonathan.beckett | last post by:
I have been working on a client project recently that is using winforms ..NET user controls within web pages in Internet Explorer, and need to find out how to make the user control communicate back...
0
by: benjamin.soulier | last post by:
Hello everyone, here is the problem I got : I have a Base Web User Control (like a user control containing a border, for design purpose). In this User Control, I put a PlaceHolder, and I put a...
9
by: J055 | last post by:
Hi I have a standard asp page which uses a MasterPage. The MasterPage contains a User control. How can I access a public method in the User control from my WebForm page? I can't move the method...
10
by: Cirene | last post by:
I know that sometimes referring to controls deep in a page using a Master Page can be funky. For a website using a standard header/footer/nav, do you prefer using User Controls for the common...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.