Javascript not registering/executing after button click
Posted
by rs
on Stack Overflow
See other posts from Stack Overflow
or by rs
Published on 2010-05-25T20:28:11Z
Indexed on
2010/05/25
20:31 UTC
Read the original article
Hit count: 231
I have a textbox which i convert to tinymce textbox using tinymce.js file. I'm trying to add a new script with database fields substituted based on selection made from dropdownlist to page using registerstartupscript.
In page load
protected sub page_load(byVal sender as object, byval e as EventArgs) handles me.load
AddScriptToPage()
if not page.ispostback() then
session("fname") = nothing
end if
end sub
Script Method
Sub AddScriptToPage()
dim _script = " c.onRenderMenu.add(function(c, m) { " & _
add_columns() & _
"}); "
ClientScript.RegisterStartupScript(Me.GetType(), keyword,_script)
End Sub
function add_columns() as string
dim ret_string = String.empty
select case ddlList.selectedvalue
case 1
sqlcommand = "xyz"
case 2
sqlcommand = "xyz"
case 3 //Load from excel
sqlcommand = nothing
end select
if sqlcommand isnot nothing then
executereader()
while reader.read()
ret_string = ret_string & reader("column")
end while
elseif session("fname") isnot nothing
dt = getdatatable(session("fname").tostring()) //method that opens oledb connection and returns columns
for each dr in dt.rows
ret_string = ret_string & dr("column")
next
end if
add_columns = ret_string
end function
When excel file is uploaded to server this event is called
protected sub btnclick(byVal sender as object, byval e as EventArgs)
if hasfile then 'i have custom properties set after control validation
'Upload file
'set session value with filepath
session("fname") = filepath
'call js register event
AddScriptToPage()
end if
end sub
When i click upload button i'm calling AddScriptToPage, and debug it it hits AddScripttoPage event and executes it but it doesn't showup on page. It should show column names in tinymce editor but it doesn't. But when i click another button on the same page it shows (becos session has the filename).
On Upload button click page flow:
- Page load - AddScriptToPage is executed (registers scripts with no columns)
- Then AddScriptToPage in btnclick event is executed (registers scripts with columns)
Why is this script not getting registered even though it is executed on vb code on uploadclick event? And why does it show up after another button click and not original button click that calls this event?
© Stack Overflow or respective owner