jquery thickbox not working in 2005 ASP.NET - asp.net

public void DisplayThickBox(Page page, int width, int height)
{
string script = "<script type='text/javascript'>";
script += "$(document).ready(function(){";
script += "tb.show('null', 'auto-insurance-redirect.aspx?keepThis=true&TB_iframe=true&height=" + height.ToString() + "&width=" + width.ToString() + "',null);";
script += "});";
script +="</script>";
ScriptManager.RegisterStartupScript(page, page.GetType(), "", script, true);
}
^^^Method to display the thickbox...^^^
DisplayThickBox(this, 518, 321);
^^^Call to method in the click event of the button that fires it...^^^
Page is just refreshing and the thickbox is never displayed. I'm trying to call the javascript manually since im doing some other stuff before i display the thickbox in the code behind...

Sounds like you're calling this on a button click event which would postback to the server. You'll need to register the javascript on the client and call it from javascript, not thru server side code. What you have now is a startup script which should run when the page loads, that's not really what you want.

Looking at your javascript parameters:
"tb.show('null', 'auto-insurance-redirect.aspx?keepThis=true&TB_iframe=true&height=" + height.ToString() + "&width=" + width.ToString() + "',null);"
I notice that some parameters are separated by & and others are separated by &. Maybe this is the problem.

Got it fixed, no idea how...I had tried so many things and everything was getting dirty and clustered, so I took everything out and started back from blank and it worked right off the bat.
Thanks everyone for their help!

Related

Create Temporary Page

can someone point me to the right direction
I need a code to dynamically create a temporary Web Pop-up Page which I'll declare the HTML Content in ASP.NET Using VB
reason for this function is that I am trying to make Application Form printer and I need to print the current page with the
<script>window.print();</script>
You could generate the entire HTML as string and then use as below:
window.open("data:text/html;charset=utf-8,<head></head><body><h3>Test Document</h3></body><script>window.print();</script>");
Basically,
window.open("data:text/html;charset=utf-8," + YOUR_HTML + "<script>window.print();</script>");
Copy paste the below script in a browser to test:
data:text/html;charset=utf-8,<head></head><body><h3>Test Document</h3></body><script>window.print();</script>
== Updates ==
Aspx.vb Code
Dim htmlText As String = "<head></head><bod‌​y><h3>Test Document</h3></body>".Normalize()
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "tempWindow", "<script>openTempWindow('" + htmlText + "')</script>", False)
Aspx Code
<script type="text/javascript">
function openTempWindow(content) {
var win = window.open("");
win.document.write(content);
}
</script>
You can achieve that by manipulating the response. This is one way to dinamically create an HTML document. For example:
HttpContext.Current.Response.Write("<html>
<body>
<h1>Something to print</h1>
</body>
<script>window.print();</script>
</html>")
In order to make it a popup window, in your base page you can implement window.open() function after, lets say, a button click. For example:
window.open("../pageReturningDynamicHTML.aspx?someParam=someValue")
In the provided link you can find more examples on how to open a window as popup with settings as sizes and more.

On Asp.net Button click open link in new maximized window

I have a button in Update panel in my page. on button click event dependendant on the text boxes entered i m buliding an url and have to open that url in new window.
i have tried:
i) window open .. but it opens un maximized , not a fully maximized window. i tried setting its height to screen hieght,,but the requirement is full window only, shouldnt need to be maximize every time i open window.
<Asp:button OnClick="Btn1_Click" />
//in code behind
protected void Btn1_Click(object sender, EventArgs e)
{
//my code to generate url
// In below lines im trying to open window
//Im ont using OnClientClick becoz..the button is in Update panel
ScriptManager.RegisterStartupScript(btnLoadReport.Page,
Btn1.GetType(), "", "window.open('" + myUrl+ "','','height=' + screen.height + ',width=' + screen.width + ',resizable=yes,scrollbar=yes,toolbar=yes,menubar=yes,location=yes,top=0, left=0');", true);
}
or can i create a hyperlink click event dynamically on button click event.. and how do i try that?
any ideas and samples would be appreciated.
Thanks,
Ahmed
try this: OnClientClick="window.open('url')"
the c# file you write,
button.attributes.add("onclick","javascript:function1()");
in the aspx page,write the below javascript function
function function1()
{
window.open("pagename",other attributes whose values are to be passed to other page);
}
Did not understand you the first time. Try this. Im guessing your not using update panels here right? cause if you are you should use scriptmanger.register.. instead of client script
Btn1_Click()
{
//my code to bulid url
ClientScript.RegisterStartupScript(this.GetType(),"Redirection","window.open('www.google.com', '_blank')",true);
}
<Asp:button OnClick="Btn1_Click" />
try this please : window.open(url, '_blank');
EDIT : look at this link dude example for opening new tab
My issue got resolved by adding 'chromemode=yes' in parameters.. like below..
window.open(url, 'chromemode=yes, scrollbars=yes' );
thank you all for your answers :)

Jquery tab selection on asp.net postback

I have an asp.net page with some JQuery tabs. Everything works ok.
I added a dropdownlist in one of the tabs, that causes a postback. After the postback I want the same tab to be selected.
I initialize the tabs as:
<script type="text/javascript">
$(document).ready(function() {
var $myTabs = $(".tabsDiv").tabs();
</script>
Then, on the PageLoad event, I inject a script to select the tab:
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "TabSelect", "$myTabs.tabs('select', 1);", true);
For some reason this doesn't work. The script is running but the tabs are not selected.
Is it because the RegisterClientScriptBlock places the script in the bottom of the page and, for some reason, it runs too late?
Any help is appreciated.
Thx in advance
Calling $myTabs.tabs('select', 1); I think results in an error. $myTabs is not a global variable. It's scope is only in $(document).ready(function() { ... });
Can you try with $(".tabsDiv").tabs('select', 1); and see if it works?
Regards...
It might run too early... bottom of the page is good, try this instead:
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "TabSelect",
"$(document).ready(function() { $myTabs.tabs('select', 1); });", true);
Basically, it also runs this code at the ready event.

Redirect from pop up window

how can i redirect to other page from pop up window with response.redirect.
I'm assuming that you're wanting to do this when the user presses a button or something on the popup. You can use ClientScript.RegisterStartupScript function to get ASP.Net to put some JavaScript in the right place so that it's executed as soon as the postback has completed. Something like this...
public void RedirectParent(string url)
{
string js = "";
js += "window.opener.location.href='" + url + "';";
js += "window.close();";
ClientScript.RegisterStartupScript(this.GetType, "redirect", js, true);
}
You can remove the window.close() line if you want to keep the popup open, but I'm guessing that you want to close it automatically.
The "redirect" bit on the last line is just the name that you want to assign to the script - this can be anything you wish.
Once popup is opened to a given URL you cannot use server side script to redirect the parent. You need to use javascript inside the popup:
if (opener && !opener.closed) {
opener.location.href = "http://www.example.com/somenewurl";
}

Need a postback handle from a clicked dynamic hyperlink control in ajax

The scenario...I have a list of dynamic hyperlink controls on an ajax panel that link directly to a WORD doc located on a share. Clicking any link opens WORD client side (I set the file association to do that so the IE browser doesn't try to open it instead).
LinkButtons won't work because it doesn't do a direct link to the doc from the browser and I don't want server automation or activex, since I want each client to open the doc using their own box as if they had simply clicked on the document itself.
But I need to change an image in an image control once they've clicked on the hyperlink. In other words, I need the link to sit on top of a control that does cause a postback so I can get at the posting controls ID and do my thing. I'm also trying to avoid client side scripting though I'm sure there may be a convoluted way to do that.
Here is the code in the loop that creates the dynamic link. I started with just the hyperlink control, then this code is messing with adding a hyperlink to a label, that's why it's showing as it is:
Label lblWordLink = new Label();
HyperLink hrefLetter = new HyperLink();
hrefLetter.Text = items.letterName;
hrefLetter.NavigateUrl = folderForPackageLetters + items.letterName + wordDocExtension;
hrefLetter.ID = "standardLettersHref_" + items.letterName;
lblWordLink.Text = "<a href='" + hrefLetter.NavigateUrl.ToString() + "'>" + items.letterName + "</a>" ;
tRow.Cells[1].Controls.Add(lblWordLink);
I'm looking for a way to let the link open the doc and at the same time postback. Is there a way to layer the link control on top of another control such that the link just links and the control beneath causes a postback?
32U
Fixed: the answer gave the clue. On the server, during dynamic control creation I did:
HyperLink hrefLetter = new HyperLink();
hrefLetter.ID = "standardLettersHref_" + items.letterName;
hrefLetter.Text = items.letterName;
hrefLetter.NavigateUrl = folderForPackageLetters + items.letterName + wordDocExtension;
hrefLetter.Attributes.Add("OnClick", "letterHrefClick('" + items.letterName + wordDocExtension + "')");
tRow.Cells[1].Controls.Add(hrefLetter);
then client side I pushed a value into a hidden control inside the ajax panel when the hyperlink control was clicked and forced submit:
function letterHrefClick(link) {
//alert(link);
form1.hdnLetterClick.value = link;
form1.submit();
}
After the submit, back on server side, I got the value in the Page_Load event:
string x = hdnLetterClick.Value;
nice!
update...
An even better way to do this... in the javascript postback use:
__doPostBack("hdnLetterClick", "somevalue");
then in the codebehind in the Page_Init you can do (not for button or imgbutton):
string postbackControlID = Request.Params.Get("__EVENTTARGET");
string postbackArgument = Request.Params.Get"__EVENTARGUMENT");
to get at what you need. This is better if dealing with dynamic controls so you can control state during control recreation.
If you give your link an onclick attribute, those javascript actions should also be executed when the link is selected.

Resources