Anyone knows how to open a twitter bootstrap modal, from code behind?
I want to open the modal based on some requeriment at the moment of the save. Something like "Hey there's no stock, pick up one of the following options to continue (discard, reserve...) and press that button (that may do a postback for continue)"
I'm using ASP.NET web forms.
FYI,
I've seen this strange behavior before in jQuery widgets. Part of the key is to put the updatepanel inside the modal. This allows the DOM of the updatepanel to "stay with" the modal (however it works with bootstrap).
How about doing it like this:
1) show popup with form
2) submit form using AJAX
3) in AJAX server side code, render response that will either:
By default Bootstrap javascript files are included just before the closing body tag
I took these javascript files into the head section right before the body tag and I wrote a small function to call the modal popup:
then I could call the modal popup from code-behind with the following:
Finally I found out the problem preventing me from showing the modal from code-behind. One must think that it was as easy as register a clientscript that made the opening, like:
But this never worked for me.
The problem is that Twitter Bootstrap Modals scripts don't work at all when the modal is inside an asp:Updatepanel, period. The behaviour of the modals fail from each side, codebehind to client and client to codebehind (postback). It even prevents postbacks when any js of the modal has executed, like a close button that you also need to do some sever objects disposing (for a dirty example)
I've notified the bootstrap staff, but they replied a convenient "please give us a fail scenario with only plain html and not asp." In my town, that's called... well, Bootstrap not supporting anything more that plain html. Nevermind, using it on asp.
I thought them to at least looking what they're doing different at the backdrop management, that I found causes the major part of the problems, but... (justa hint there)
So anyone that has the problem, drop the updatepanel for a try.
Maybe this answer is so late, but it's useful.
to do it,we have 3 steps:
1- Create a modal structure in HTML.
2- Create a button to call a function in java script, to open modal and set
display:none
in CSS .3- Call this button by function in code behind .
you can see these steps in below snippet :
HTML modal:
Hidden Button:
Script Code:
code behind:
this solution is one of any solutions that I used it .
This method of opening the Modal would not display the Modal for me. I found this as a work arround.
I removed:
Than I added an asp:label named lblJavaScript and in code behind call:
Now the Modal will display.