سؤال

I am having VB Script in ASPX page.I need to use that Script in codeBehind in Page _load with in a For loop,for each iteration.

My Code is :- (.ASPX Page with VB Script. )

<script type="text/vbscript" language="vbscript" >
sub wordit()
'Opens Word application and does some process   
end sub
</script>

VB Code Behind Part:-

          For i As Integer = 1 To colSelRowIndex

            CheckboxTemplateId = colSelRowKeys(i).ToString 'I get the ID from here 
            ViewState("TemplateID") = CheckboxTemplateId 'I need to send the value to the sub routines 
            hen()'sub
            den()'sub
            cs.RegisterStartupScript(cstype, csname1 & i, "wordit();", True)
        Next

I need to open a word doc for an ID and another document for another ID from the loop.

هل كانت مفيدة؟

المحلول

Try this:

For i As Integer = 1 To 10
    cs.RegisterStartupScript(cstype, csname1 & i, "wordit();", True) 
Next

That second argument in that function call is looking for a unique key. This is a feature, to prevent accidentally programmatically adding the same script more than once. If you want to do it on purpose, you need a unique key each time.

But that you want to do this at all indicates a possible fundamental misunderstanding about what's going on. While your server code (including Page_Load) is running, your client page in the web browser doesn't exist. The purpose of the server code is always to generate an html response to web request. The server code can never directly manipulate a page DOM.

Obviously this is true for a first request to a page in session: the server must first generate the initial page to send the client. But even on subsequent postbacks, the browser will destroy the prior instance of a page. The server must rebuild the entire page from scratch. Every. Time. While this happens, the page you're looking at in your browser window is only a sort of after-image. The browser has already destroyed any prior DOM, and is waiting for the server to supply a whole new set of HTML.

I also wonder at your use of vbscript, rather than javascript. Using vbscript pretty much guarantees you're page will only work with Internet Explorer.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top