|
Javascript is always at client side and I can not think of any application having two users logged in from one browser.
It would be better if you tell us what you are actaully trying to achieve.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
hii...
i have populated my menu control dynamically.i want the menu items to allign left
but i dont found any such property.also i want to fix the width of menuitems.how can i do it...
reply...thanks..
|
|
|
|
|
Why you not using CSS for fixing such kind of things ?
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
|
In an ASP.NET C# application, I have a class called "MyPanel" derived from Panel. MyPanel contains a Button with a Click event. The click event is handled in the MyPanel class.
When I store any MyPanel objects in the Session variable and retrieve them on a postback, the Click events seem to disappear. When the user clicks a Button inside the MyPanel object, a postback happens, but the click events don't get executed. I have to "relink" the click handlers when I retrieve the MyPanel objects from Session.
I am using InProc Session mode. I had though I could store even complex objects in the Session variable. But I lose the events in the objects.
Is this explainable?
Thanks,
Mark
|
|
|
|
|
Why would you store them in a session ? How do the clicks 'disappear' ? A click event exists only for a postback. Once you store it in the session, it's just an object, it can't fire anything from the session and there's no event to store.
The other issue is that your controls are regenerated on every postback. So, I doubt you'd have a reference to the same control, which means that any clicks that occured, would not occur in the controls you have in your session, as they are not all references to the same control.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
A few questions: Is your mypanel object an actual object on the page, or are you initializing it at run-time? Are you wiring up the events by hand? Where are the events wired (what page event)? Why are you manually storing the object in the session?
If you are re-linking the event handlers with each postback, I imagine that the click event itself is getting lost.
1) click event is generated - postback
2) event is re-linked to a handler (in page load?)
3) original click event should be handled, but the event handler was re-assigned in step 2...event is lost.
I'm guessing that your object is not actually part of the page, but is created at run-time. I'm also guessing that this is why you are losing events. I would try to come up with a solution that involved the mypanel object as a 'static' object on the page. You will also avoid having to put the mypanel object in session state as a result.
Best of luck.
Rob
tagyurit.com
|
|
|
|
|
Thanks for the responses.
To Rob...My MyPanel objects are objects on the page that are being dynamically created at runtime. Therefore at runtime, various user actions cause MyPanel objects to be created. When they are instantiated, the code links up click events for the buttons within.
Since these dynamic MyPanel objects must persist between post-backs, my thought was to store them in an Array-List which is stored in the Session object. It works well, but I find the Click events no longer work after I pull them out of the Session object after the post-back. I must relink the Click events at that time.
I am just wondering why.
Thanks,
Mark
|
|
|
|
|
In a sense, all event handlers are re-linked at postback. The difference is that objects that are static on your page have their handlers automatically linked by the framework. Since your control is dynamic, you must do it yourself.
This link may be of interest to you:http://msdn.microsoft.com/en-us/library/ms178472.aspx[^]
Is it possible to place the panels on the page as static objects and change their visibility property to hide them if you don't need them? Do you have variable set of panels preventing you from doing this? Give me a little more background - maybe there is a simpler solution.
Rob
http://tagyurit.com
|
|
|
|
|
Thanks Rob. I didn't realize that events must be relinked at postback. Since these "MyPanels" are created dynamically, I guess the viewstate doesn't handle that for me and I will have to relink the events myself? That is how I am interpreting what you are saying.
I am still learning about ASP.NET. I will investigate static objects. Maybe that is what I need to use.
Thanks,
Mark
|
|
|
|
|
Hi everyone!
I'm working with a data grid and I would like to tie in some javascript. I have a field with a label that will have a numerical value. Two buttons are also in this cell and I want one to increase that number and the other to decrease it. Is there a way during the grid.databind event that I can add the client side onclick event to the buttons which will in turn be able to find the current row's label control client ID? This way, I can have each button call a single javascript function but pass it the row's label control that I want it to affect. I've done this before with static controls on the page, but I'm not sure how to start this one because (I'm assuming) each label on the gridview will have a different client side ID.
Thanks!
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.
|
|
|
|
|
Its easy...
First write your javascript that might change the value of a textbox, say like this:
<script>
function increaseValue(textId)
{
var elem = document.getElementById(textId);
if(!!elem)
elem.value = parseInt(elem.value) + 1;
}
function decreaseValue(textId)
{
var elem = document.getElementById(textId);
if(!!elem)
elem.value = parseInt(elem.value) - 1;
}
</script>
Now in your GridView.RowDataBound event write :
TextBox tb = e.Item.FindControl("tbValue") as TextBox;
Button btnIncr = e.Item.FindControl("btnIncr") as Button;
btnIncr.Attributes.Add("onclick", "javascript:increaseValue('" + tb.ClientID + "');");
Button btnDecr = e.Item.FindControl("btnDecr") as Button;
btnIncr.Attributes.Add("onclick", "javascript:decreaseValue('" + tb.ClientID + "');");
Now you see when the page is rendered it will hold the buttons with appropriate Onclick Event handlers to process the textbox tb.
Hope you like this solution.
|
|
|
|
|
Oh! slap me in the forehead! I was thinking of the gridview as a whole and how the heck I would find the controls after it's completed. I didn't even think of attacking it at the RowDataBound level. Thanks for the nudge in the right direction!!!
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.
|
|
|
|
|
It happens to all of us..
|
|
|
|
|
Just wanted to update incase anyone else needs to do something similar. I found this site to be helpful as well: GridView and Javascript Also, For some reason the page continued to post back and cause an invalid post back error on the server, but this is resolved by adding the following parameters to the buttons:
buttonPlus.PostBackUrl = "javascript:;";
buttonMinus.PostBackUrl = "javascript:;";
Also, you might need to do e.Row.FindControl if e.Item.FindControl is unavailable.
Thanks!!!
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.
|
|
|
|
|
Yes.. you are right ...
Thanks for update.
cheers.
|
|
|
|
|
Hi Abhishek,
Actually, I believe I spoke too soon! Turns out it fixed the post back problem but broke the rest of my server side asp.Button controls on this page (after I issue the very first javascript command that is). I was playing around with one of my other sites and tried using a server side button that calls a validation javascript function. I got it to call the function but it acted quite similar to this issue in that it would either call the function but still issue the post back to the server each time (without having button.postbackurl="javascript:;"; ) or would call the function but then never actually post back once the validation boolean was set to true (button.postbackurl="javascript:;"; The only way I've found around this so far is to not use an asp.net button control and just create the <input type="button" value="submit" onclick="validateForm();" /> , but that only works with the static pages. I've been googling it for the past day now, but any documentation or references I find give me the impresion that it should just work. Have you ever run into an issue like this? I'm thinking there's a parameter that I'm overlooking, but I can't find it. I've tried setting button.UseSubmitBehavior = true; and / or button.CausesValidation = false; but they just end up causing required validation problems.
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.
|
|
|
|
|
yes. .For <asp:button use
btn.Attributes.Add("onclick", "javascript:");
this is the best option to have client side event. Otherwise in the designer you might use
onClientClick="javascript:"
|
|
|
|
|
dang..it is calling the javascript but still issuing the post back to the server and throwing a validation error. I did view the source and I believe the problem lies in the fact that all of the buttons are of type "submit". Is there a way I can programatically change them to type="button" instead? I tried button.Attributes.Add("type", "button") but they are still ending up in the browser as type="submit". Doesn't make any sense. I've seen a ton of forums and articles now indicating that what you've suggested should just work.
[UPDATE] It dawned on me that it was probably because I never changed the UseSubmitBehavior parameter on the button. If I change this to false, then the javascript fires without trying to submit, however it is still posting back and refreshing the page, causing my javascript changes to dissapear during the server's page load. The only way I've found so far to keep the page from refreshing is adding the PostBackURL parameter, but if I do that then all of my buttons on the page seem to "inherit" this and then they won't work. grr!
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lb1 = (Label)e.Row.FindControl("label1");
Button btminus = (Button)e.Row.FindControl("minus_qty");
btminus.UseSubmitBehavior = false;
btminus.Attributes.Add("onclick", "javascript:decreaseQuantity('" + lb1.ClientID + "');");
Button btplus = (Button)e.Row.FindControl("plus_qty");
btplus.UseSubmitBehavior = false;
btplus.Attributes.Add("onclick", "javascript:increaseQuantity('" + lb1.ClientID + "');");
}
Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.
|
|
|
|
|
I am trying to write some client-side script from the code behind page using the RegisterStartupScript method of the ClientScriptManager. The script is trying to add an OnChange event handler for an asp:DropDownList control. I am using the ClientID property of the DropDownList in the script. The script is not working. When I tried stepping through the document.all collection to see if the proper ID was being generated, I found that NONE of the elements in the document.all collection had an ID, even though all of the controls on this aspx page have IDs assigned. It appears the IDs assigned in the aspx page are not being passed on to the client's html page. I am using a MasterPage, but this particular control is in the content page, not the MasterPage. What is going on here?
|
|
|
|
|
I think you must use dropdown.ClientID to get that ..
Can you post the code you pass as script in RegisterStartupScript... so that I could clarify where you are wrong...
|
|
|
|
|
Thanks. But since I posted that message, I found the problem. It had to do with some hidden fields on the form. Thanks anyway.
|
|
|
|
|
Great to see you solved yourself.
|
|
|
|
|
Good Day
its Friday and am Tired. i request your assistance here
Am binding a grid with RRS info. now there is a Field that Displays the URL and a i made it to display a Hyperlink in that field like this
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkUserID" runat="server" NavigateUrl='<%# Eval("Link")%>' Text='<%#Eval("Link") %>'>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
Now it appears as a link, Good, but the Problem is that when i click the link it does not navigate to the URL.
Thanks
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
modified on Friday, September 4, 2009 10:23 AM
|
|
|
|
|
Vuyiswa Maseko wrote: when i click the link it does not navigate to the URL
Which URL get opened after you click on link?
Show us how you are saving url in table.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|