troubleshooting Question

using "ClientScript.RegisterClientScriptBlock'

Avatar of Relegence
RelegenceFlag for Israel asked on
JavaScriptASP.NETWeb Applications
4 Comments1 Solution7281 ViewsLast Modified:
Hello,

I am writing a c# asp.net application. I have a page with a "asp:LinkButton".
When pressing the linkButton I want to open another window by calling a javascript function using:

ClientScript.RegisterClientScriptBlock(this.GetType(), "openWin", "<script>openChannelsWin('newSection')</script>");

On 'openChannelsWin' function on client side, i am trying to fetch some values from controls on the screen, before opening the window, but then i get errors.

For example, I am trying to fetch the following value:
var siteName = document.getElementById("txtName").value;

The problem is that "document.getElementById("txtName")" is null and i get an exception.

The strange thing is that if I press "View Source" on my page, i do see all of the controls, but if i press the linkButton, i get an exception as if non of my controls are on the page.

What am I doing wrong here?

Thank you

My linkButton:
<asp:LinkButton ID="lnkSecChannels" runat="server" Text="Click to select channels..." OnClick="lnkSecChannels_Click"></asp:LinkButton>
 
My code behind function:
 protected void lnkSecChannels_Click(object sender, EventArgs e)
{
        ClientScript.RegisterClientScriptBlock(this.GetType(), "openWin", "<script>openChannelsWin('newSection')</script>");
}
 
My javascript function (openWin is a function i wrote):
function openChannelsWin(src)
{
var siteName = document.getElementById("txtName").value;            
openWin("../channels.aspx?siteName=" + siteName,'Channels','height=300')
}
ASKER CERTIFIED SOLUTION
Irzana

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros